我正在运行 Windows 2003 Service Pack 2。我有一个按需运行的批处理文件。我希望每次运行批处理文件时都会发送一封电子邮件。邮件很简单,就是一句话表明批处理文件运行了;每次都是一样的。
我尝试了几件事来完成这件事。我想到了telnet,但我不知道如何将一组命令重定向到telnet; Windows 批处理文件没有 Unix 风格的“此处文档”,并且调用"telnet <scriptfile"
where 脚本文件包含发送电子邮件的命令不起作用。我还在互联网上找到了一些使用 CDO.Message 的解决方案,但我以前从未使用过它,并且不断收到我不理解的错误消息。
如何从 Windows 批处理文件发送简单的电子邮件?
Max 的建议是正确的,他建议使用 Windows 脚本来实现这一点,而无需在计算机上安装任何其他可执行文件。如果您将 IIS SMTP 服务设置为使用“智能主机”设置转发出站电子邮件,或者计算机也恰好运行 Microsoft Exchange,那么他的代码将起作用。否则,如果未配置此选项,您将发现电子邮件堆积在消息队列文件夹 (\inetpub\mailroot\queue) 中。因此,除非您可以配置此服务,否则您还希望能够指定用于发送消息的电子邮件服务器。为此,您可以在 Windows 脚本文件中执行以下操作:
Set objMail = CreateObject("CDO.Message")
Set objConf = CreateObject("CDO.Configuration")
Set objFlds = objConf.Fields
objFlds.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'cdoSendUsingPort
objFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.your-site-url.com" 'your smtp server domain or IP address goes here
objFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 'default port for email
'uncomment next three lines if you need to use SMTP Authorization
'objFlds.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "your-username"
'objFlds.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "your-password"
'objFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'cdoBasic
objFlds.Update
objMail.Configuration = objConf
objMail.FromName = "Your Name"
objMail.From = "[email protected] /cdn-cgi/l/email-protection"
objMail.To = "[email protected] /cdn-cgi/l/email-protection"
objMail.Subject = "Email Subject Text"
objMail.TextBody = "The message of the email..."
objMail.Send
Set objFlds = Nothing
Set objConf = Nothing
Set objMail = Nothing
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)