
Sometimes we want to enable our servers/desktops to be able to send email without setting up a full featured mail server or configuring postfix to route through Gmail.
sSmtp is an extremely simple, resource conserving, SMTP server that will allow your desktop or server to send email. In this article we are going to use sSMTP to send outgoing email through Gmail.
Install sSMTP
Debian/Ubuntu users can Install with this command or click here to open up apt:
We need to then need to edit, ‘/etc/ssmtp/ssmtp.conf’:
root=username@gmail.com
mailhub=smtp.gmail.com:587
rewriteDomain=
hostname=username@gmail.com
UseSTARTTLS=YES
AuthUser=username
AuthPass=password
FromLineOverride=YES
Then add each account that you want to be able to send mail from by editing, ‘/etc/ssmtp/revaliases‘:
root:username@gmail.com:smtp.gmail.com:587
localusername:username@gmail.com:smtp.gmail.com:587
Now try sending an email
You can send an email through your favorite email client, like ‘mutt‘, or type:
You will then type your message, hit enter and ‘ctrl+d‘
Now that you have a simple outgoing email server setup, you can do all sorts of neat things:
- Configure cron jobs to send log reports to your email address
- Alert you of all kinds of system changes
- Send email alerts when your computer reaches a certain temperature
- Send email through PHP, Python, Ruby, and Perl
Was this information useful?
16 Responses
-
[...] Setting up an email server on Nix machine is invaluable to keep an eye on multiple machines. Lets face it, often times Nix machines run so well that we sometimes forget to login and check on them every once and awhile. Why not make them check on their selves by scripting them to email you when they need some maintenance love? [...]
-
Blake
7-1-2009
Just wanted to mention that if your using sSMTP from the CLI, that the format should look like this;
sudo ssmtp someemail@email.com
To: someemail@email.com
From: youremail@email.com
Subject: enter_subject_hereenter_body_here (then press enter when done to get a newline)
Then press ctrl-D -
Mark Sanborn
7-1-2009
Thanks Blake!
-
[...] We can change this default behavior by changing the MAILTO variable. Note: This will not work if you have not setup an email server. [...]
-
[...] talked about some of the benefits of setting up an email server in Linux and how you can use python to send email. Now we are going to look at how you can send email from [...]
-
linux admin
9-18-2009
nice tutorial im going to try this on my linux server
-
linux admin
9-18-2009
my file /etc/ssmtp/ssmtp.conf doesn’t contain any of the following
UseSTARTTLS=YES
AuthUser=username
AuthPass=passworddo i need to add those ?
-
linux admin
9-18-2009
i added them and it worked however isn’t it insecure to store the password as plain text ?
-
Mark Sanborn
9-18-2009
@Linuxadmin
Yes it kinda is… You can chmod 600 it. If you find a better way definitely let me know.
-
[...] You must have some sort of mailer daemon installed. See How to setup Gmail with sSMTP. You can try it out by editing the appropriate parts of the script and then [...]
-
Barrydocks
10-18-2009
Excellent howto, I have been struggling to set up postfix or exim to act as a simple e-mail reporting system for my server. This worked first time. I assume I just forward all the kernel messages from root to a user and then to an external account?
Is there anyway of changing the sender name, I simply get messages from “root”?
Thanks
-
Badcam
11-29-2009
@Barrydocks
Just follow what Blake does and include a
From: youremail@email.com when sending emails.You can also do:
From: AnythingYouLike
I’d like to know if there’s a way to have this set in the ssmtp.conf file.
Cheers.
-
romulus
11-29-2009
Barrydocks, or anyone else who has that problem – you can add To, From and Subject fields (others I don’t know about). See above, the comment by Blake from 7/1/2009.
-
G O Free =:)
1-29-2010
Oh yeah…
As above…
Don’t use ’sudo’ unless you want your emails to appear from ‘root’.
Add ’smtp’ directory to the PATH of your normal USER, and run as normal user.
(Edit ‘/etc/ssmtp/revaliases’ with your normal user name as “localusername”, as in tutorial.)
Thanks!
-
[...] from your domain registrars control panel. Also if the amount of mail is less you can use sSMTP to send mail via GMail, which will give guaranteed delivery to inbox. If sending from your server, [...]




6-29-2009