1

I use this script to send emails to people I send short messages all the time, as well as updating my rememberthemilk todo's from launchy.

When I need to add a new task I just

  1. Hit alt+space (invokes launchy)
  2. type rr
  3. hit tab
  4. type "this is my todo"
  5. press enter

What I would like to do, is to not have to write the "" since the slow me down a lot.

Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
schema = "http://schemas.microsoft.com/cdo/configuration/"
Flds.Item(schema & "sendusing") = 2
Flds.Item(schema & "smtpserver") = "smtp.GMAIL.com"
Flds.Item(schema & "smtpserverport") = 465
Flds.Item(schema & "smtpauthenticate") = 1
Flds.Item(schema & "sendusername") = "YOU@GMAIL.COM"
Flds.Item(schema & "sendpassword") = "YOURPASSWORD"
Flds.Item(schema & "smtpusessl") = 1
Flds.Update

With iMsg
.To = "RECIEVER@MAIL.COM"
.From = "jacob <YOU@GMAIL.COM"
.Subject = wscript.arguments.item(0)
.HTMLBody = message
.Sender = " "
.Organization = " "
.ReplyTo = " "
Set .Configuration = iConf
SendGMAILGmail = .Send
End With

set iMsg = nothing
set iConf = nothing
set Flds = nothing
user1603548
  • 572
  • 6
  • 21

1 Answers1

1

I'm not sure I fully understand the question, but I'm assuming that your task is run by passing in whatever you type as the command line arguments to the script, and because you are using wscript.arguments.item(0) as the subject you need to add quotes to ensure that the full subject is included in the first argument.

Using the (slightly crazy) code from here, the following should work

Set oWMISrvc = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\.\root\cimv2")
sProcName = Mid(wsh.fullname, InstrRev(wsh.fullname, "\") + 1)
Set cProcesses = oWMISrvc.ExecQuery( _
    "select * from win32_process where Name = '" & sProcName & "'")
For Each oProcess in cProcesses
  If Instr(lcase(oProcess.Commandline), lcase(wsh.scriptname)) > 0 Then
    sCmdLine = oProcess.Commandline
  End If
Next

iNamePos = instr(lcase(sCmdLine), lcase(Wscript.ScriptName))

sArguments = trim(mid(sCmdLine, iNamePos + len(Wscript.ScriptName)))

Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
schema = "http://schemas.microsoft.com/cdo/configuration/"
Flds.Item(schema & "sendusing") = 2
Flds.Item(schema & "smtpserver") = "smtp.GMAIL.com"
Flds.Item(schema & "smtpserverport") = 465
Flds.Item(schema & "smtpauthenticate") = 1
Flds.Item(schema & "sendusername") = "YOU@GMAIL.COM"
Flds.Item(schema & "sendpassword") = "YOURPASSWORD"
Flds.Item(schema & "smtpusessl") = 1
Flds.Update

With iMsg
.To = "RECIEVER@MAIL.COM"
.From = "jacob <YOU@GMAIL.COM"
.Subject = sArguments
.HTMLBody = message
.Sender = " "
.Organization = " "
.ReplyTo = " "
Set .Configuration = iConf
SendGMAILGmail = .Send
End With

set iMsg = nothing
set iConf = nothing
set Flds = nothing

Alternatively just concatenate all provided arguments:

sArguments = ""
For i = 0 to Wscript.Arguments.Count - 1
  if i > 0 Then
    sArguments = sArguments + " "
  End If
  sArguments = sArguments + Wscript.Arguments(i)
Next

Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
schema = "http://schemas.microsoft.com/cdo/configuration/"
Flds.Item(schema & "sendusing") = 2
Flds.Item(schema & "smtpserver") = "smtp.GMAIL.com"
Flds.Item(schema & "smtpserverport") = 465
Flds.Item(schema & "smtpauthenticate") = 1
Flds.Item(schema & "sendusername") = "YOU@GMAIL.COM"
Flds.Item(schema & "sendpassword") = "YOURPASSWORD"
Flds.Item(schema & "smtpusessl") = 1
Flds.Update

With iMsg
.To = "RECIEVER@MAIL.COM"
.From = "jacob <YOU@GMAIL.COM"
.Subject = sArguments
.HTMLBody = message
.Sender = " "
.Organization = " "
.ReplyTo = " "
Set .Configuration = iConf
SendGMAILGmail = .Send
End With

set iMsg = nothing
set iConf = nothing
set Flds = nothing

the method to use will depend on your requirements. The first method will retain all quotes on the command line while the second method will ignore the spacing between words.

zelanix
  • 1,204
  • 7
  • 12