sen email without qoutes vbs

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

Posted 2014-07-10T22:01:28.400

Reputation: 484

Answers

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

Posted 2014-07-10T22:01:28.400

Reputation: 1 134

the second was the one I needed, i.e. ignore my spaces – user1603548 – 2014-07-11T11:20:44.210

here is the error code https://www.evernote.com/shard/s4/nl/505992/3b290a31-aa6d-4894-bfd2-444ac9fbd5ec and here is the line it complains on:

– user1603548 – 2014-07-11T11:33:56.187

SendGMAILGmail = .Send – user1603548 – 2014-07-11T11:34:51.310

I can't see your error :( – zelanix – 2014-07-11T14:49:44.553

You did change your email and password, right? It works fine for me, but if I run it as it is I get the same error. – zelanix – 2014-07-12T11:39:05.597

other tiny error. spotted it. – user1603548 – 2014-07-12T14:54:39.053