VBScript 在不运行 Outlook 的情况下发送电子邮件
我编写了一个每晚运行的自动化测试,我想在测试完成后每晚通过电子邮件发送结果。
为了做到这一点,我尝试将以下内容放在批处理文件的末尾:
Set MyApp = CreateObject("Outlook.Application")
Set MyItem = MyApp.CreateItem(0)
With MyItem
.To = "[email protected]"
.Subject = "Subject"
.ReadReceiptRequested = False
.HTMLBody = "resport"
End With
MyItem.Send
但是,这会导致电子邮件无法发送,因为我的 Outlook 未打开,因为测试在后台运行,并且我无权访问用户界面。
无论如何,是否可以在不实际在计算机上运行 Outlook 的情况下发送此电子邮件。
谢谢!
I have written an automated test that runs each night, and I would like to email the results each night once the test is finished.
In order to do this I attempted to put the following at the end of my batchfile:
Set MyApp = CreateObject("Outlook.Application")
Set MyItem = MyApp.CreateItem(0)
With MyItem
.To = "[email protected]"
.Subject = "Subject"
.ReadReceiptRequested = False
.HTMLBody = "resport"
End With
MyItem.Send
However, this is causing the email to not send because my Outlook is not open, as the test is run in the background, and I have no access to the UI.
Is there anyway to send this email without actually running outlook on the machine.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以在 VBScript 中使用 CDO.Message 对象在没有 Outlook 的情况下发送电子邮件。您需要知道 SMTP 服务器的地址才能使用此地址:
如果您的 SMTP 服务器需要用户名和密码,请将这些行粘贴到
MyEmail.Configuration.Fields.Update
行上方:更多信息使用 CDO 通过 VBScript 发送电子邮件可以在下面的链接中找到:
http://www.paulsadowski.com/wsh/cdo.htm
You can send email without Outlook in VBScript using the CDO.Message object. You will need to know the address of your SMTP server to use this:
If your SMTP server requires a username and password then paste these lines in above the
MyEmail.Configuration.Fields.Update
line:More information on using CDO to send email with VBScript can be found on the link below:
http://www.paulsadowski.com/wsh/cdo.htm
这是您从其他服务(例如私人电子邮件)发送电子邮件的方式
我测试了它,它有效。
This is how you can send emails from other services like private email
I tested it, it's working.
是的。 Blat 或任何其他独立的 SMTP 邮件程序。 Blat 是一个功能相当齐全的 SMTP 客户端,从命令行运行
Blat 在这里
Yes. Blat or any other self contained SMTP mailer. Blat is a fairly full featured SMTP client that runs from command line
Blat is here
以下是架构文档的当前链接:
https://learn.microsoft.com/en-us/previous-versions/office/developer/exchange-server-2003/ms873029(v=exchg.65)
而不是使用对象引用再说一次,一个漂亮的
With
语句看起来会更好:关于
smtpusessl
字段的额外说明:这仅适用于 TLS 类型端口。它与 STARTTLS 协议不同。使用 STARTTLS 时只需将其设置为false
即可。Here is a current link to the schema documentation:
https://learn.microsoft.com/en-us/previous-versions/office/developer/exchange-server-2003/ms873029(v=exchg.65)
Instead of using the object references over and over again, a nice
With
statement will look better:Extra note about the
smtpusessl
field: This works on a TLS type port only. It is not the same as the STARTTLS protocol. Simply set it tofalse
when using STARTTLS.