不帶qoutes的sen電子郵件vbs

不帶qoutes的sen電子郵件vbs

我使用這個腳本向我一直發送簡訊的人發送電子郵件,並更新我的記得牛奶todo 來自 launchy。

當我需要新增任務時,我只需

  1. alt+空格(調用發射的
  2. 類型RR
  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") = "[email protected]"
Flds.Item(schema & "sendpassword") = "YOURPASSWORD"
Flds.Item(schema & "smtpusessl") = 1
Flds.Update

With iMsg
.To = "[email protected]"
.From = "jacob <[email protected]"
.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

我不確定我是否完全理解這個問題,但我假設您的任務是透過將您輸入的任何內容作為命令列參數傳遞給腳本來運行的,並且因為您使用wscript.arguments.item(0)作為主題,所以您需要添加引號來確保完整的主題包含在第一個參數中。

使用(有點瘋狂)代碼這裡,以下應有效

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") = "[email protected]"
Flds.Item(schema & "sendpassword") = "YOURPASSWORD"
Flds.Item(schema & "smtpusessl") = 1
Flds.Update

With iMsg
.To = "[email protected]"
.From = "jacob <[email protected]"
.Subject = sArguments
.HTMLBody = message
.Sender = " "
.Organization = " "
.ReplyTo = " "
Set .Configuration = iConf
SendGMAILGmail = .Send
End With

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

或者,只需連接所有提供的參數:

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") = "[email protected]"
Flds.Item(schema & "sendpassword") = "YOURPASSWORD"
Flds.Item(schema & "smtpusessl") = 1
Flds.Update

With iMsg
.To = "[email protected]"
.From = "jacob <[email protected]"
.Subject = sArguments
.HTMLBody = message
.Sender = " "
.Organization = " "
.ReplyTo = " "
Set .Configuration = iConf
SendGMAILGmail = .Send
End With

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

使用方法取決於您的要求。第一種方法將保留命令列上的所有引號,而第二種方法將忽略單字之間的空格。

相關內容