Command Line SMTP Mailer for Batch Jobs Bmail is a free but lean command line SMTP mail sender. Don't get fooled into playing $$$ for huge executables. Bmail allows the user to automate the sending of email messages containing log files, data downloads or error messages on Win32 based computers. Together with the freeware utility mpack, you can also send MIME encoded attachments. C:\>bmail -s mars -t cpeacock@max -f root@neptune -h -a "Data Download Script is not Working Correctly" -b "The script on neptune has stopped getting data" Command Line SMTP Emailer V1.07 Copyright(C) 2002-2004 Craig.Peacock@beyondlogic.org Opening connection to mars [192.168.0.10] on port 25 220 mars ESMTP Postfix (Release-20010228) 250 Ok: queued as 04168186A7 Bmail has the following options - C:\>bmail /? Command Line SMTP Emailer V1.07 Copyright(C) 2002-2004 Craig.Peacock@beyondlogic.org Usage: bmail [options] -s SMTP Server Name -p SMTP Port Number (optional, defaults to 25) -t To: Address -f From: Address -b Text Body of Message (optional) -h Generate Headers -a Subject (optional) -m Filename (optional) Use file as Body of Message -c Prefix above file with CR/LF to separate body from header -d Debug (Show all mail server communications) The mail server name, To: Address and From: Address fields are mandatory. Multiple recipients can be specified after the -t by separating them by a comma. The SMTP port number is seldomly used, but can be used to force mail to be sent to a non standard port. The user has two choices for specifying the body of the message. If a single line body is all that is required, it can be specified on the command line using the -b option. In this case you may want to also use -a to specify a subject and -h to add TO: and FROM: headers to the body of your message. However if a larger message body is required, such as a pre-formatted text email, log file, data file or a mime encoded attachment etc then the body of the message can be read from a file. The file can be specified by the -m switch. In this case the user can choose to use the -h, -a and -b switches in conjunction with the file, or manually enter these headers to the top of your file. Usage Examples Below are just some examples showing the use of bmail. If you simply need to send a quick one line email you can use the following example, C:\>mail -s smtp.server -t cpeacock@max -f root@neptune -h -a "Subject e.g. Fatal Error" -b "Body of message e.g. Fatal Error occurred in cgi script, secure.cgi" Command Line SMTP Emailer V1.07 Copyright(C) 2002-2004 Craig.Peacock@beyondlogic.org Opening connection to mars [192.168.0.10] on port 25 220 mars ESMTP Postfix (Release-20010228) 250 Ok: queued as B952E42C6F Pipes can be utilised to redirect stdout from a process(s) to a log file, then send this file as the body of the message should an error result. C:\>[ Some Process ] > stdout.txt C:\>if errorlevel 1 bmail -s smtp.server -t cpeacock@max -f root@neptune -h -a "Process Dump" -m stdout.txt -c Command Line SMTP Emailer V1.07 Copyright(C) 2002-2004 Craig.Peacock@beyondlogic.org Opening connection to mars [192.168.0.10] on port 25 220 mars ESMTP Postfix (Release-20010228) 250 Ok: queued as 4AFD1186B7 Note should be taken of the -c switch which separates the body from header with a CR/LF combination. While with most mail clients it doesn't make any difference, some versions of Outlook will display an empty body, treating your stdout.txt body as part of the header. With mpack you can use bmail to send mime attachments. C:\>echo Please find attached today's build of mail.exe > body.txt C:\>mpack -s "Today's Build" -d body.txt -c application/exe -o body.msg mail.exe C:\>bmail -s smtp.server -t cpeacock@max -f root@neptune -h -m body.msg Command Line SMTP Emailer V1.07 Copyright(C) 2002-2004 Craig.Peacock@beyondlogic.org Opening connection to mars [192.168.0.10] on port 25 220 mars ESMTP Postfix (Release-20010228) 250 Ok: queued as 485CB186A7