GET-IT: TEAMS DAY | 1-Day Free Virtual Conference all about Teams. Here on - 8/12/20 GET-IT: TEAMS DAY - 8/12/20

Send Mail from Script

How can I send an e-mail message from a script?

There are a few simple ways to send e-mail messages from the command prompt or from within a script. Here are 5 of my favorites (listed at no particular order):

Method #1: MAILSEND

If you want to send a single e-mail message or hundreds of them and do it all from a single batch file or command you should use the MAILSEND program written by Muhammad A Muquit.

This is extremely useful in E2K. Whenever you create new mailbox-enabled users you need to send them an e-mail message before you can begin to manipulate mailbox permissions etc. I use MAILSEND to automate this task.

MAILSEND is a simple program to send mail via SMTP for MS Windows NT/2000/XP. To use it, you must know the address or IP address of the SMTP server you wish to use.

MAILSEND is a console application, you can run it from command shell or by clicking on the app from file explorer. You can use it in many ways. I’m using as the IP address of the SMTP server as an example, change this to your valid one. Some example are shown below:

Interactive usage

Non-interactive usage

Everything the program needs can be fed from stdin or from a file.


message can be passed from stdin as well:

If no message file is specified, it will ask to type the message:

Also a file can be created with SMTP server, from, to, cc, bcc, subject and mail body which can be used as a single input to the program. For example, if you create a file like below:

  • The first line is the SMTP server address or IP address.
  • The second line is the domain used in SMTP HELO.
  • The third line is the From address.
  • The fourth line the To address/es. They can be command separated.
  • Right after the To the mail body starts.

Now this file can be fed as follows:

You can see the mail getting delivered if you specify the -v flag. Note: in non-interactive mode, you can not specify Cc, Bcc or Subject in the file. If you need any of them specify with appropriate flags.


Or from HERE (local download if author’s site ever goes dead).

Method #2: A short VBS script

I thank Yuval Sinai for the quick tip.

Open Notepad and enter the following text:

Lamer note: You should enter your own sender and recipient e-mail addresses. Same goes for the subject and text body.

Save the file as something.vbs

Double-clicking it or calling it from another script will activate it.

Method #3: Another short VBS script

Open Notepad and enter the following text:

Another Lamer note: Again, you should enter your own sender and recipient e-mail addresses. Same goes for the subject and text body.

Save the file as something.vbs

Double-clicking it or calling it from another script will activate it.

Method #4: Using a Send Mail

You could also download and use my own Send Mail which is quite easy to use (perhaps easier than all the above).

Method #5: Bmail

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.

Bmail has the following options:

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.

Download Bmail + Instructions

Related Topics:

  • Exchange Server

    Don't have a login but want to join the conversation? Sign up for a Petri Account