Sending emails from the Terminal is very efficient especially for short messages. In this post I’m going to explain how to set up sSMTP in order to send emails through your Gmail right from the Terminal. Once you have sSMTP set up you can also use cron jobs to get you computer/server to automatically email you when there is a problem. Please note that this only works on Linux (and Mac OS X).
First we install sSMTP:
sudo apt-get install ssmtp
Configure sSMTP by editing ssmtp.conf:
vi /etc/ssmtp/ssmtp.conf
You can delete everything in that file and just replace it with this:
root=your_username@gmail.comUseSTARTTLS=YESUseTLS=YESmailhub=smtp.gmail.com:465rewriteDomain=gmail.comFromLineOverride=YESAuthUser=usernameAuthPass=********
(If the gmail is a Google Apps account then use the full email address for the AuthUser.)
Now we need to edit revaliases to add each user account we want to send mail from:
vi /etc/ssmtp/revaliases
Add:
root:username@gmail.com:smtp.gmail.com:587user:username@gmail.com:smtp.gmail.com:587
And we’re done!
To send emails from the Terminal either type:
echo “email content” | mail -s “email subject” recipient_email@domain.com
or:
ssmtp recipient_email@domain.com
Then enter the following:
To:Â recipient_email@domain.comFrom: your_email@gmail.comSubject: this is your email subjectAnd here you write the content of the email
And to send the email, press: CTRL+D
(N.B. The empty line between the Subject and the content of the email must not be omitted)
You can also send emails using a text file:
ssmtp recipient_email@domain.com < message.txt
(The contents of message.txt must be in the same format as above)
Depending on your machine’s set up, it may be necessary to remove sendmail and install mailutils:
sudo service sendmail stopsudo apt-get remove sendmailsudo apt-get install mailutils
If you have any questions please leave a comment!
How did you know that it was my live-long dream to send emails from the terminal?? Thank you for giving me a reason to live!!
xSSx
Really usefull trick, I found this site ages ago and this was the first post I read, and I had no idea what it meant because I hadn’t even heard of linux back then, I recently converted to ubuntu, and was browsing the site when I saw this, and suddenly saw what wisdom it was telling me 😀
Hi there, of course this post is genuinely good and I have learned lot of things from it regarding blogging.
thanks.
Hi ,
Very useful. How does one add a cc or bcc in this scheme?
– Jonathan