отправьте электронное письмо без qoutes vbs

542
user1603548

Я использую этот сценарий для отправки электронных писем людям, которым я постоянно отправляю короткие сообщения, а также для обновления задач по запоминанию молока при запуске.

Когда мне нужно добавить новое задание, я просто

  1. Хит alt + пробел (вызывает запуск )
  2. тип рр
  3. хит- вкладка
  4. типа "это моя задача"
  5. нажмите Ввод

Что я хотел бы сделать, так это не писать «», так как это сильно меня тормозит.

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 
1

1 ответ на вопрос

1
zelanix

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:" _ & "!\\.\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.

второй был тот, который мне нужен, то есть * игнорировать мои пробелы * user1603548 9 лет назад 0
вот код ошибки https://www.evernote.com/shard/s4/nl/505992/3b290a31-aa6d-4894-bfd2-444ac9fbd5ec и вот строка, на которую он жалуется: user1603548 9 лет назад 0
SendGMAILGmail = .Send user1603548 9 лет назад 0
Я не вижу твоей ошибки :( zelanix 9 лет назад 0
https://www.dropbox.com/s/x27tdqa48k1z8zv/ScreenClip%202014-07-11.png user1603548 9 лет назад 0
Вы изменили свой адрес электронной почты и пароль, верно? Он прекрасно работает для меня, но если я запускаю его как есть, я получаю ту же ошибку. zelanix 9 лет назад 0
другая крошечная ошибка. заметил это. user1603548 9 лет назад 0

Похожие вопросы