Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send mail from a Windows script

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

like image 816
Jörgen Lundberg Avatar asked Sep 30 '08 09:09

Jörgen Lundberg


People also ask

Can you send an email from a batch file?

Yes, you can use another batch file to call the email send one, with all the details as parameters.

How do I send an email with Blat EXE?

What blat does is forward the email to your email spooler/server. Blat is very simple to use; just download the utility, place blat.exe in the c:\windows\system32 folder, and point it to your email server. Once you've done that, you can use the blat command to send emails from scripts. The blat website is www.blat.net.

What is Febootimail?

Febooti Command Line Email is a powerful but easy to use email-sending utility that supports all basic and advanced email client's sending capabilities · Quick start.


1 Answers

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>]
like image 194
Nathan Hartley Avatar answered Oct 07 '22 13:10

Nathan Hartley