Difference between revisions of "SSMTP"

From ArchWiki
Jump to: navigation, search
(syntax fixes, updates)
Line 38: Line 38:
 
</pre>
 
</pre>
  
Change the file permissions of {{ic|/etc/ssmtp/ssmtp.conf}} because the password is printed in plain text (so that other users on your system cannot see your Gmail password). You also need to change group to mail, to avoid "/etc/ssmtp/ssmtp.conf not found" error. Users who can send mail need to belong to "mail" group.
+
Change the file permissions of {{ic|/etc/ssmtp/ssmtp.conf}} because the password is printed in plain text (so that other users on your system cannot see your Gmail password).  
chmod 640 /etc/ssmtp/ssmtp.conf
+
{{bc|chmod 640 /etc/ssmtp/ssmtp.conf}}
chown root.mail /etc/ssmtp/ssmtp.conf
+
  
In {{ic|/etc/ssmtp/revaliases}} you will need to define your aliases:
+
Change the config file group to mail to avoid "/etc/ssmtp/ssmtp.conf not found" error.
root:username@gmail.com:smtp.gmail.com:587
+
{{bc|chown root:mail /etc/ssmtp/ssmtp.conf}}
mainuser:username@gmail.com:smtp.gmail.com:587
+
  
To test whether the Gmail server will properly forward your email:
+
Users who can send mail need to belong to "mail" group (must log out and log back in for changes to be used).
echo test | mail -s "testing ssmtp setup" username@somedomain.com
+
{{bc|gpasswd -a mainuser mail}}
  
'username@somedomain.com' can be any valid email address you have access to to test. Gmail's smtp server will forward to your own Gmail account too if you would like to use that.
+
Create aliases for local usernames
 +
{{hc|/etc/ssmtp/revaliases|root:username@gmail.com:smtp.gmail.com:587
 +
mainuser:username@gmail.com:smtp.gmail.com:587}}
 +
 
 +
To test whether the Gmail server will properly forward your email:
 +
{{bc|<nowiki>echo test | mail -v -s "testing ssmtp setup" username@somedomain.com</nowiki>}}
  
  
Line 55: Line 58:
  
  
If you want to change the 'From' text displayed in the mail sent, edit the {{ic|/etc/passwd}} and modify the user alias.
+
Change the 'From' text by editing {{ic|/etc/passwd}} to receive mail from 'root@myhostname' instead of just 'root'.
For example, I was always getting mails from 'root' whic is useless because I have several machines at home.
+
{{bc|chfn -f root@myhostname root
I changed the root's alias from 'root' to 'root@myhostname'.
+
chfn -f mainuser@myhostname mainuser}}
<pre>
+
Which changes {{ic|/etc/passwd}} to:
[root@myhostname ~]# grep root /etc/passwd
+
{{hc|grep myhostname /etc/passwd|root:x:0:0:root@myhostname,,,:/root:/bin/bash
root:x:0:0:root@myhostname:/root:/bin/bash
+
mainuser:x:1000:1000:mainuser@myhostname,,,:/home/mainuser:/bin/bash}}
</pre>
+
  
As an alternate method for sending emails, even using a Gmail alias, you can create a text file:
+
An alternate method for sending emails is to create a text file and send it with 'ssmtp' or 'mail'
<pre>
+
{{hc|test-mail.txt|To:username@somedomain.com
To:username@somedomain.com
+
 
From:youraccount@gmail.com
 
From:youraccount@gmail.com
 
Subject: Test
 
Subject: Test
  
This is a test mail.
+
This is a test mail.}}
</pre>
+
  
Save the file and send it through ssmtp:
+
Send the {{ic|test-mail.txt}} file
ssmtp youraccount@gmail.com < test
+
{{bc|mail username@somedomain.com < test-mail.txt}}
  
 
===Attachments===
 
===Attachments===

Revision as of 18:57, 25 May 2012


Note: This program still works as of 11-14-2009 but note that SSMTP is no longer being developed. You might want to consider an alternative like MSMTP.
Note: 22 Feb 2010: SSMTP seems to be maintained. SSMTP 2.6.4-1 was put in the Arch Linux packages at 2009-11-26. And in Debian unstable version 2.6.4-3 was put in their unstable repository on 2010-02-09 and move to testing just 10 days later: http://packages.qa.debian.org/s/ssmtp.html

SSMTP is a program to deliver an 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.

Installation

To install SSMTP:

pacman -S 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)
root=username@gmail.com

# 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
mailhub=smtp.gmail.com:587

# The address where the mail appears to come from for user authentification.
rewriteDomain=gmail.com

# The full hostname
hostname=localhost

# Use SSL/TLS before starting negotiation 
UseTLS=Yes
UseSTARTTLS=Yes

# Username/Password
AuthUser=username
AuthPass=password

# Email 'From header's can override the default domain?
FromLineOverride=yes

Change the file permissions of /etc/ssmtp/ssmtp.conf because the password is printed in plain text (so that other users on your system cannot see your Gmail password).

chmod 640 /etc/ssmtp/ssmtp.conf

Change the config file group to mail to avoid "/etc/ssmtp/ssmtp.conf not found" error.

chown root:mail /etc/ssmtp/ssmtp.conf

Users who can send mail need to belong to "mail" group (must log out and log back in for changes to be used).

gpasswd -a mainuser mail

Create aliases for local usernames

/etc/ssmtp/revaliases
root:username@gmail.com:smtp.gmail.com:587
mainuser:username@gmail.com:smtp.gmail.com:587

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

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


If you receive the error
send-mail: Cannot open mailhub:25
be sure the user is a member of the "mail" group.


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

chfn -f root@myhostname root
chfn -f mainuser@myhostname mainuser

Which changes /etc/passwd to:

grep myhostname /etc/passwd
root:x:0:0:root@myhostname,,,:/root:/bin/bash
mainuser:x:1000:1000:mainuser@myhostname,,,:/home/mainuser:/bin/bash

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

test-mail.txt
To:username@somedomain.com
From:youraccount@gmail.com
Subject: Test

This is a test mail.

Send the test-mail.txt file

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

Attachments

This method does not work with attachments. If you need to be able to add attachments, install and configure Mutt and Msmtp and then go see the tip at nixcraft.

References