windows - 从 Windows 脚本发送邮件

标签 windows email scripting smtp wsh

我想通过 Windows Server 2003 Standard Edition 上的脚本发送邮件。我认为服务器设置几乎是开箱即用的。

邮件服务器是 Exchange 服务器,当您在内部网络上时,您可以使用普通的旧 SMTP。我在我的机器上用 Perl 完成了它,但不幸的是 Perl 在服务器上不可用。

有没有一种简单的方法可以从 .bat 文件或任何其他不需要安装一些额外软件的方式来做到这一点?

编辑:
感谢您的快速回复。 "blat"thingie 可能会工作正常,但使用 wscript 我不必使用单独的二进制文件。

我第一次编辑和选择答案时没有看到 PhiLho 的帖子。我无需在此处复制代码。

只需将脚本保存到一个文件中,比如 sendmail.vbs,然后从命令提示符中调用它,如下所示:
wscript 发送邮件.vbs

最佳答案

可以使用 Wscript,使用 CDO:

Dim objMail

Set objMail = CreateObject("CDO.Message")

objMail.From = "Me <Me@Server.com>"
objMail.To = "You <You@AnotherServer.com>"
objMail.Subject = "That's a mail"
objMail.Textbody = "Hello World"
objMail.AddAttachment "C:\someFile.ext"

---8<----- You don't need this part if you have an active Outlook [Express] account -----
' Use an SMTP server
objMail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

' Name or IP of Remote SMTP Server
objMail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
    "smtp.server.com"

' Server port (typically 25)
objMail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

objMail.Configuration.Fields.Update
----- End of SMTP usage ----->8---

objMail.Send

Set objMail=Nothing
Wscript.Quit

更新:在那里找到更多信息:VBScript To Send Email Using CDO 默认情况下,它似乎使用 Outlook [Express],因此它在我的计算机上不起作用,但您可以使用给定的 SMTP 服务器,这对我来说效果很好。

关于windows - 从 Windows 脚本发送邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/152323/

相关文章:

c++ - 无需源代码即可调试/绕过 BSOD

c - 如何使用命令提示符运行 .exe 文件?

email - 胡言乱语的垃圾邮件 - 这是什么意思?

ElasticSearch:从 Painless 脚本中的嵌套字段计算 arcDistance

java - 使用命令行和外部库在 ide 之外运行我的 jar 时出错

Windows 与 Linux 上的 C++ - 常见问题?

Magento 交易电子邮件 Logo 和 HTTPS (SSL)

c# - 用封闭的 HREFS 替换电子邮件和 HREFS

vim - 在 Vim 中编写常见任务的脚本

输出函数结果的 Bash 脚本