Click here to Skip to main content
15,867,914 members
Articles
Tip/Trick
(untagged)

Send Email from Command Line using GMail Account

Rate me:
Please Sign up or sign in to vote.
4.00/5 (1 vote)
9 Jul 2012CPOL 61.6K   4   2
Send Gmail from DOS command line using MAILSEND.exe

Introduction

The script sends email from command line (MS-DOS) using GMail account.

Background

Download mailsend.exe from here.

Using the Code Examples

Plain Text Email/SMS via SSL

mailsend.exe -to anyemail@gmail.com  
-from myemail@gmail.com  -ssl -smtp smtp.gmail.com -port 465 -sub 
"The subject line test %time%" -M "This is body text of the message. 
%date% %time% sending. SD." +cc +bc -q -auth-plain -user "win4me" 
-pass "secret" 

Plain Text Email/SMS with Name of sender (via STARTTLS)

mailsend.exe -to anyemail@gmail.com  
-name "Automation" -from myemail@gmail.com -starttls -smtp smtp.gmail.com 
-port 587 -sub "The subject line test %time%" 
-M "This is body text of the message. %date% %time% sending. 
SD." +cc +bc -q -auth-plain -user "win4me" -pass "secret" 

Using default env variable instead of - pass

set SMTP_USER_PASS=secret 
<pre>mailsend.exe -to anyemail@gmail.com  
-from myemail@gmail.com  -ssl -smtp smtp.gmail.com -port 465 
-sub "The subject line test %time%" 
-M "This is body text of the message. %date% %time% sending. 
SD." +cc +bc -q -auth-plain -user "win4me"  

Attached image to email

mailsend.exe -to anyemail@gmail.com 
-from myemail@gmail.com  -ssl -smtp smtp.gmail.com -port 465 -sub "
Mail with attachment %time%" -M "This is body text of the message. 
%date% %time% sending. SD." +cc +bc -q -auth-plain -user "win4me" 
-pass  "secret"  -attach "C:\imagefile.jpg,image/jpg" 

In-line image in email body

mailsend.exe -to anyemail@gmail.com 
-from myemail@gmail.com  -ssl -smtp smtp.gmail.com -port 465 
-sub "Mail with inlime image %time%" -M "This is body text of the message. 
%date% %time% sending. SD." +cc +bc -q -auth-plain -user "win4me" 
-pass  "secret"  -attach "C:\imagefile.jpg,image/jpg,i"  

For more options, see:

mailsend -h
mailsend examples  

History

  • 07/08/2012: Originally posted

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
SuggestionSame thing with Powershell Pin
Andrewdh2-Jul-13 18:56
Andrewdh2-Jul-13 18:56 
Thanks Jack, it's a useful utility. I was trying to do this the other day on a win server and realised it can be done with a powershell script meaning you don't need to install anything.

I've added the email script to this link to send email using powershell from the windows command line.[^]
Check out my developer blog for more tips on wpf, mvc, wcf, sql server, msbuild and test.

GeneralMy vote of 4 Pin
Carlos Luis Rojas Aragonés17-Jul-12 6:40
professionalCarlos Luis Rojas Aragonés17-Jul-12 6:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.