Send Email from a .bat script

( 1 Vote ) 

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 192.168.0.1 -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

Comments   

djamel
0 # djamel 2012-03-15 23:32
i can't send attached files with a mailsend.exe
Reply | Reply with quote | Quote
djamel
+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
Reply | Reply with quote | Quote
admin
0 # 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.
Reply | Reply with quote | Quote
mia
+2 # mia 2012-04-18 16:41
How do you attach more than one file? Can you use wildcards?
Reply | Reply with quote | Quote
admin
0 # admin 2012-06-07 15:51
Simply repeat -attach "image.jpg",a switch for each file you want to attach.
Reply | Reply with quote | Quote
Jorge
0 # 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?

Thanks,
Jorge
Reply | Reply with quote | Quote
admin
0 # admin 2012-08-07 13:48
Don't think mailsend accepts wildcards. What are you trying to achieve?
Reply | Reply with quote | Quote
Lisa
0 # Lisa 2012-06-06 17:54
It doesn't seem to like spaces in my from email address...any suggestions?
Reply | Reply with quote | Quote
admin
0 # admin 2012-06-06 19:32
What do you mean? You can't have spaces in valid email address...
Reply | Reply with quote | Quote

Add comment


Newsletter

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.

Privacy Policy                     Login