我想从Windows Server 2003 Standard Edition上的脚本发送邮件。我认为服务器设置非常开箱即用。

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

是否有一种简单的方法可以从.bat文件或其他不需要安装其他软件的方式执行此操作?

<代码>编辑:结果 感谢您的快速回复。 “blat” thingie可能会正常工作但是使用wscript我不必使用单独的二进制文件。

我第一次编辑和选择答案时没有看到PhiLho的帖子。我不需要在这里复制代码。

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

有帮助吗?

解决方案

使用CDO可以使用Wscript:

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

更新:在那里找到更多信息:

其他提示

如果服务器发生(我意识到这个问题有多久)安装了Powershell v2,那么CmdLet Send-MailMessage就可以在一行中完成。

Send-MailMessage [-To] <string[]> [-Subject] <string> -From <string> [[-Body] <string>] [[-SmtpServer] <string>] [-Attachments <string[]>] [-Bcc <string[]>] [-BodyAsHtml] [-Cc <string[]>] [-Credential <PSCredential>] [-DeliveryNotficationOption {None | OnSuccess | OnFailure | Delay | Never}] [-Encoding <Encoding>] [-Priority {Normal | Low | High}] [-UseSsl] [<CommonParameters>]

如果您安装了outlook / exchange,您应该能够使用CDONT,只需创建一个mail.vbs文件并在批处理文件中调用它(有趣的是它们在同一个目录中)

wscript mail.vbs

用于VBScript代码签出

http://support.microsoft.com/kb/197920

http://www.w3schools.com/asp/asp_send_email.asp

忘记他们这两个链接谈论ASP的事实,它应该可以作为一个独立的脚本与iis一起工作。

我认为你必须安装一些可以从WScript调用的ActiveX或其他组件,例如: http://www.activexperts.com/ActivEmail/ 和: http://www.emailarchitect.net/webapp/SMTPCOM/developers/scripting。 ASP

否则,您必须自己编写WScript中的整个SMTP逻辑(如果可能,不确定)。

将CDONTS与Windows Scripting Host(WScript)一起使用

是否有一种方法可以在不引用外部架构URL的情况下发送。 http://schemas.microsoft.com/cdo/configuration/

这是非常无用的,因为不能假设所有盒子都有外部互联网访问权限在本地交换机内部发送邮件。有没有办法在本地保存这些网址的信息?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top