VBScript在不运行Outlook的情况下发送电子邮件
我已经写了一个每天晚上运行的自动测试,我想在测试完成后每天晚上通过电子邮件发送测试结果 为此,我尝试在批处理文件末尾添加以下内容:VBScript在不运行Outlook的情况下发送电子邮件,vbscript,sendmail,outlook-2007,Vbscript,Sendmail,Outlook 2007,我已经写了一个每天晚上运行的自动测试,我想在测试完成后每天晚上通过电子邮件发送测试结果 为此,我尝试在批处理文件末尾添加以下内容: Set MyApp = CreateObject("Outlook.Application") Set MyItem = MyApp.CreateItem(0) With MyItem .To = "a@a.com" .Subject = "Subject" .ReadReceiptRequested = False .HTMLBod
Set MyApp = CreateObject("Outlook.Application")
Set MyItem = MyApp.CreateItem(0)
With MyItem
.To = "a@a.com"
.Subject = "Subject"
.ReadReceiptRequested = False
.HTMLBody = "resport"
End With
MyItem.Send
但是,这会导致电子邮件无法发送,因为我的Outlook未打开,因为测试是在后台运行的,并且我无法访问UI
是否仍然可以发送此电子邮件而不在计算机上实际运行outlook
谢谢 是的。Blat或任何其他独立的SMTP邮件程序。Blat是一个功能相当全面的SMTP客户端,从命令行运行
您可以使用CDO.Message对象在VBScript中发送不带Outlook的电子邮件。您需要知道SMTP服务器的地址才能使用此地址:
Set MyEmail=CreateObject("CDO.Message")
MyEmail.Subject="Subject"
MyEmail.From="name@domain.com"
MyEmail.To="a@a.com"
MyEmail.TextBody="Testing one two three."
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'SMTP Server
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.server.com"
'SMTP Port
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
MyEmail.Configuration.Fields.Update
MyEmail.Send
set MyEmail=nothing
如果SMTP服务器需要用户名和密码,请将这些行粘贴到MyEmail.Configuration.Fields.Update
行上方:
'SMTP Auth (For Windows Auth set this to 2)
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")=1
'Username
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername")="username"
'Password
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword")="password"
有关使用CDO使用VBScript发送电子邮件的详细信息,请访问以下链接:
非常感谢!这帮了大忙!我请求了服务器的名称,希望能在周一之前收到。然后我将选择此作为接受的答案。如果我希望用户名和机器名包含在邮件中,比如
userxyz登录到machinexyz
,该怎么办。实际上,我有一个Windows7客户端,我想通过发送邮件来跟踪登录情况。因此,我将调用此代码作为登录事件任务。我有管理广告的Windows Server 2008。所以我应该在哪里配置规则-在win 7客户端或win服务器上。那会有什么不同吗?也可以使用vbs
实现这一点吗?