Send Email from a .bat script

You can use mailsend.exe to send emails from the command line or a script via a known SMTP server. More information and more ways to use this little useful utility here.

In MS Exchange environment I used this method to send emails from batch jobs to internal email addresses. If you want to use this to send messages to external recipients you may need to configure Exchange relay options. Some additional info here.

An example of using mailsend.exe:

  • Place mailsend1.16.exe in any folder
  • In the same folder create send.bat file.
  • Place following command in send.bat (obviously changing domain, server IP address, and other details to match your environment)
    mailsend1.16.exe -d your-domain-name -smtp -t This email address is being protected from spambots. You need JavaScript enabled to view it. -f This email address is being protected from spambots. You need JavaScript enabled to view it. -sub "Subject of your message" -M "message body text"
  • Run send.bat to send your email
  • If you having any issues add switch -v to enable verbose mode
  • If you want to add an attachment add -attach "image.jpg",a where image.jpg file name of your attachment.

Tested on:
Exchange 2007
Windows Server 2003
Windows XP
Windows 7


# Lisa 2012-06-06 17:54
It doesn't seem to like spaces in my from email address...any suggestions?
# admin 2012-06-06 19:32
What do you mean? You can't have spaces in valid email address...
+2 # mia 2012-04-18 16:41
How do you attach more than one file? Can you use wildcards?
# Jorge 2012-08-07 13:17
Did you ever figure out if you can use wildcards to attach files with mailsend, and if so, how?

# admin 2012-08-07 13:48
Don't think mailsend accepts wildcards. What are you trying to achieve?
# admin 2012-06-07 15:51
Simply repeat -attach "image.jpg",a switch for each file you want to attach.
+1 # djamel 2012-03-15 23:36
the conaint of txt file wich is supposed to be my attachement apears as message not as a txt attachement ,it can be because a mime but i don't knew how to deal with
thanks for yr help
# admin 2012-03-16 11:06
I updated the article with latest version of mailsend.exe (1.16). Some switches are slightly different so download and try again following new instructions.

I just did a test attaching a .txt file and it was included as an attachment.
# djamel 2012-03-15 23:32
i can't send attached files with a mailsend.exe


Subscribe to receive occasional updates on new posts.
Your email will not be used for any other purpose and you can unsubscribe at any time.
Please wait