Difference between revisions of "SSMTP"

From ArchWiki
Jump to navigation Jump to search
m (Update to match restyled AUR template (ArchWiki:News 2015/05/24))
Line 3: Line 3:
Install the package {{Pkg|ssmtp}} from the [[official repositories]].
[[Install]] the package {{Pkg|ssmtp}}.
==Forward to a Gmail Mail Server==
==Forward to a Gmail Mail Server==

Revision as of 00:32, 15 June 2015

SSMTP is a program which delivers email from a local computer to a configured mailhost (mailhub). It is not a mail server (like feature-rich mail server sendmail) and does not receive mail, expand aliases or manage a queue. One of its primary uses is for forwarding automated email (like system alerts) off your machine and to an external email address.


Install the package ssmtp.

Forward to a Gmail Mail Server

To configure SSMTP, you will have to edit its configuration file (/etc/ssmtp/ssmtp.conf) and enter your account settings:

# The user that gets all the mails (UID < 1000, usually the admin)

# The mail server (where the mail is sent to), both port 465 or 587 should be acceptable
# See also http://mail.google.com/support/bin/answer.py?answer=78799

# The address where the mail appears to come from for user authentication.

# The full hostname

# Use SSL/TLS before starting negotiation

# Username/Password

# Email 'From header's can override the default domain?
Note: Take note, that the shown configuration is an example for Gmail, You may have to use other settings. If it is not working as expected read the man page man 8 ssmtp, please.

Create aliases for local usernames (optional)


To test whether the Gmail server will properly forward your email:

$ echo test | mail -v -s "testing ssmtp setup" tousername@somedomain.com

Change the 'From' text by editing /etc/passwd to receive mail from 'root at myhost' instead of just 'root'.

# chfn -f 'root at myhost' root
# chfn -f 'mainuser at myhost' mainuser

Which changes /etc/passwd to:

$ grep myhostname /etc/passwd


Because your email password is stored as cleartext in /etc/ssmtp/ssmtp.conf, it is important to secure the file. Securing ssmtp.conf will ensure that:

  • if any users have unprivileged access to your system, they cannot read the file and see your email password, while still letting them send out email
  • if your user account is ever compromised, the hacker cannot read the ssmtp.conf file, and therefore your email password, unless he gains access to the root account as well

To secure ssmtp.conf, do this:

Create an ssmtp group:

# groupadd ssmtp

Set ssmtp.conf group owner to the new ssmtp group:

# chown :ssmtp /etc/ssmtp/ssmtp.conf

Set the group owner of the ssmtp binary to the new ssmtp group:

# chown :ssmtp /usr/bin/ssmtp

Make sure only root, and the ssmtp group can access ssmtp.conf:

# chmod 640 /etc/ssmtp/ssmtp.conf

Set the SGID bit on the ssmtp binary.

# chmod g+s /usr/bin/ssmtp

Now, all the regular users can still send email using the terminal, but none can read the ssmtp.conf file.

Sending Email

To send email from the terminal, do:

$ echo "this is the body" | mail -s "Subject" username@somedomain.com

or interactively as:

$ mail username@somedomain.com
Note: When using mail interactively, after typing the Subject and hitting enter, you type the body. Hit Ctrl+d on a blank line to end your message and automatically send it out.

An alternate method for sending emails is to create a text file and send it with ssmtp or mail

Subject: Test

This is a test mail.

Send the test-mail.txt file

$ mail username@somedomain.com < test-mail.txt


If you need to be able to add attachments, install and configure Mutt and Msmtp and then go see the tip at nixcraft.

Alternatively, you can attach using uuencode:

$ uuencode file.txt file.txt | mail user@domain.com