Friday, December 23, 2011

How to send email from a command line using GMAIL

These instructions tell how to set up a way to send email messages from your computer using a program called SendEmail ( with GMAIL from a command line.

Why would you want to do this?

The main reason would be to let the computer notify you of conditions or issues if they occur. I originally used this program to create an automated notification if my RAID 1 mirroring failed because Windows does not notify you if your mirror fails, but it can be used for any purpose. It is easy to set up a task that if a certain error occurs it will fire off an email. I'll explain how to do this in another post.

How does it work?

Below is a bit of information as to what is happening with the sendemail program and how it works with GMAIL, but I won’t go into extensive details. As Heinlein said, “Never worry about theory as long as the machinery does what it's supposed to do.”

SendEmail is program that lets you send email from a command line. It supports Authentication using Transport Layer Security (TLS) which is one of the security protocols that GMAIL uses (the other is Secure Sockets Layer or SSL). GMAIL requires authentication using one of the two protocols.

To set up SendEmail, make a directory such as “C:\Program Files (x86)\SendEmail” and put the sendemail.exe program inside. It is a stand alone program so no installation is required.

The general settings for gmail:

SMTP server:
TLS port: 587
SSL port: 465
Username: <>
Password: <password>

Note that the SMTP port is not standard (i.e., port 25) and is different for TLS and SSL.

Can I use another email service besides GMAIL?

Yes as long as the email service will let you send email through its SMTP server and if it uses authentication, uses the TLS security protocol. You would have to look up similar information as listed above for your email service and then put them in the SendEmail command line (see below). If anyone happens to successfully use another email service, please post it in the comments and I will add it to the blog.

How do I use SendEmail?

To use SendEmail, here is the basic syntax for using it with GMAIL:
-f <from address>
-t <to address>
-u <subject>
-m <message>
-o tls=yes
-xu <>
-xp <password>

You can find other settings by running sendemail from a command line with no options and it will bring up the help screen.

To test, open a cmd window and run the program with the options you want. Here is an example:

sendemail -f <> -t <> -u Test -m Test -s -o tls=yes -xu <> -xp <yourpassword>


1. There is also a SendSMS program by the same author that lets you send text messages via command line. I haven’t tried it, but it should be straightforward.

2. I am not sure if you have an subject or body with spaces if you have to put quotes around it. When I find out I'll update.

3. The sendemail program will also let you send an attachment. I haven't had a reason to do so, but the functionality is there.

1 comment:

  1. Awesome post, Commander Dave. Been meaning to try out this utility for quite some time.