Skip to content

Instantly share code, notes, and snippets.

@sudheerit11
Created April 9, 2015 05:05
Show Gist options
  • Save sudheerit11/9e62f01fd566c0d482b2 to your computer and use it in GitHub Desktop.
Save sudheerit11/9e62f01fd566c0d482b2 to your computer and use it in GitHub Desktop.
SMTP
Install sSMTP from the package ssmtp (click the link to install), or by running the command below in your terminal:
sudo apt-get install ssmtp
sSMTP can be configured from one text file. Open /etc/ssmtp/ssmtp.conf in a text editor:
sudo gedit /etc/ssmtp/ssmtp.conf
The configuration file is very short and well commented by default. Here’s the options I use for sending mail through Gmail:
root=myemailaddress@gmail.com
mailhub=smtp.gmail.com:587
AuthUser=mygmailusername
AuthPass=mypassword
UseSTARTTLS=YES
If you’re using Gmail like I am, change the root, authuser, and authpass options to the email address, username, and password of your Google account. If you’re using another mail service you’ll need to change mailhub to the relevant SMTP server.
Once your configuration work is done, time to try sending some mail! The simplest way to do this is to run sSMTP in a terminal with a recipient email address:
ssmtp recipient_email@example.com
sSMTP will then wait for you to type your message, which needs to be formatted like this:
To: recipient_email@example.com
From: myemailaddress@gmail.com
Subject: test email
hello world!
Note the blank like after the subject, everything after this line is the body of the email. When you’re finished, press Ctrl-D. sSMTP may take a few seconds to send the message before closing.
Now it’s easy to write scripts which can send you mail. Here’s an example terminal command to send an email from the msg.txt text file:
ssmtp myemailaddress@gmail.com < msg.txt
msg.txt is a simple text using the proper formatting for sSMTP:
To: myemailaddress@gmail.com
From: myemailaddress@gmail.com
Subject: alert
The server is down!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment