Jör*_*erg 10 windows email scripting smtp wsh
我想从Windows Server 2003 Standard Edition上的脚本发送邮件.我认为服务器设置几乎是开箱即用的.
邮件服务器是Exchange服务器,当您在内部网络上时,可以使用普通的旧SMTP.我用我的机器用Perl完成了它,但不幸的是服务器上没有Perl.
有没有一种简单的方法可以从.bat文件或任何其他不需要安装其他软件的方式执行此操作?
Edit:
感谢您的快速回复."blat"thingie可能工作正常但是使用wscript我不必使用单独的二进制文件.
我第一次编辑和选择答案时没有看到PhiLho的帖子.我不需要在这里复制代码.
只需将脚本保存到文件,例如sendmail.vbs,然后从命令提示符中调用它,如下所示:
wscript sendmail.vbs
Phi*_*Lho 10
使用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
Run Code Online (Sandbox Code Playgroud)
更新:在那里找到更多信息:VBScript使用CDO发送电子邮件 默认情况下,它似乎使用Outlook [Express],因此它在我的计算机上不起作用,但您可以使用给定的SMTP服务器,这对我来说很好.
如果服务器碰巧(我意识到这个问题有多老)安装了 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>]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
46772 次 |
| 最近记录: |