从Windows脚本发送邮件 [英] Send mail from a Windows script
问题描述
我想从Windows Server 2003标准版的脚本发送邮件。我认为服务器设置是非常开箱的。
I would like to send mail from a script on a Windows Server 2003 Standard Edition. I think the server setup is pretty much out of the box.
邮件服务器是一个Exchange服务器,当您在内部网络时,您可以使用普通旧SMTP。我使用Perl从我的机器上完成了它,但不幸的是Perl在服务器上不可用。
The mail server is an Exchange one, and when you're on the internal network you can use plain old SMTP. I have done it from my machine with Perl, but unfortunately Perl is not available on the server.
有没有一个简单的方法,可以从.bat文件或任何其他方式不需要安装其他软件?
Is there an easy way of doing this from a .bat-file or any other way that doesn't require installing some additional software?
编辑:
感谢您的快速回复。 blat的东西可能会正常工作,但是使用wscript我不需要使用单独的二进制文件。
Thanks for the quick replies. The "blat" thingie would probably work fine but with wscript I don't have to use a separate binary.
我没有看到PhiLho的帖子第一次编辑并选择了一个答案。不需要我在这里复制代码。
I didn't see PhiLho's post the first time I edited and selected an answer. No need for me to duplicate the code here.
只需将脚本保存到一个文件,例如sendmail.vbs,然后从命令提示符中调用它: br>
wscript sendmail.vbs
Just save the script to a file, say sendmail.vbs, and then call it from the command prompt like so:
wscript sendmail.vbs
推荐答案
可能与Wscript,使用CDO:
It is possible with Wscript, using 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使用CDO发送电子邮件
默认情况下,它似乎使用Outlook [Express],所以它没有' t在我的电脑上工作,但你可以使用给定的SMTP服务器,这对我来说很好。
Update: found more info there: VBScript To Send Email Using CDO By default it seems it uses Outlook [Express], so it didn't worked on my computer but you can use a given SMTP server, which worked fine for me.
这篇关于从Windows脚本发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!