我使用这个脚本向我经常发短信的人发送电子邮件,以及更新我的记住牛奶来自 launchy 的待办事项。
当我需要添加新任务时,我只需
- 打alt+空格(调用发射的)
- 类型RR
- 打标签
- 输入“这是我的待办事项”
- 按 Enter 键
我想要做的是,不必写“”,因为它会让我的速度慢很多。
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
使用的方法取决于您的要求。第一种方法将保留命令行上的所有引号,而第二种方法将忽略单词之间的空格。