Send mail from a Windows script

2019-02-09 01:59发布

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.

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.

Is there an easy way of doing this from a .bat-file or any other way that doesn't require installing some additional software?

Edit:
Thanks for the quick replies. The "blat" thingie would probably work fine but with wscript I don't have to use a separate binary.

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.

Just save the script to a file, say sendmail.vbs, and then call it from the command prompt like so:
wscript sendmail.vbs

7条回答
爷、活的狠高调
2楼-- · 2019-02-09 02:35

Use CDONTS with Windows Scripting Host (WScript)

查看更多
霸刀☆藐视天下
3楼-- · 2019-02-09 02:39

I think that you'll have to install some ActiveX or other component what could be invoked from WScript, such as: http://www.activexperts.com/ActivEmail/ and: http://www.emailarchitect.net/webapp/SMTPCOM/developers/scripting.asp

Otherwise, you'll have to write the entire SMTP logic (if possible, not sure) in WScript all on your own.

查看更多
疯言疯语
4楼-- · 2019-02-09 02:50

If the server happened (I realize how old this question is) to have Powershell v2 installed, the CmdLet Send-MailMessage would do this in one line.

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>]
查看更多
ゆ 、 Hurt°
5楼-- · 2019-02-09 02:51

Is there a way you send without referencing the outside schema urls. http://schemas.microsoft.com/cdo/configuration/

That is highly useless as it can't be assumed all boxes will have outside internet access to send mail internally on the local exchange. Is there a way to save the info from those urls locally?

查看更多
Viruses.
6楼-- · 2019-02-09 02:55

I don't know if dropping a binary alongside the .bat file counts as installing software, but, if not, you can use blat to do this.

查看更多
beautiful°
7楼-- · 2019-02-09 02:57

If you have outlook/exchange installed you should be able to use CDONTs, just create a mail.vbs file and call it in a batch file like so (amusing they are in the same dir)

wscript mail.vbs

for the VBScript code check out

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

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

forget the fact they the two links speak about ASP, it should work fine as a stand alone script with out iis.

查看更多
登录 后发表回答