Wednesday, March 27, 2013

My Postfix in Ubuntu

With postfix, you'll be able to receive emails from your localhost. Here's how I go about it.

Installing

sudo apt-get install postfix
For me, the option to "General type of configuration", I choose "Satellite system".

Settings

I'm going to use Google mail server here. You need to change the relayhost if you're not using gmail.
sudo vim /etc/postfix/main.cf
relayhost = [smtp.gmail.com]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
Copy the certificate, it's optional but better we do it.
cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | sudo tee -a /etc/postfix/cacert.pem
Set the credential to Google mail server.
sudo vim /etc/postfix/sasl_passwd
[smtp.gmail.com]:587 [username]@gmail.com:[password]
sudo postmap /etc/postfix/sasl_passwd
Securing your password
sudo chmod 400 sasl_passwd.db
Finally, restart Postfix.
sudo service postfix restart

Testing

Install mailutils if you have not.
sudo apt-get install mailutils
Your choice of using mail or mailx.
echo "this is a test mail." | mail -s "test" your@email.com
echo 'It works!' | mailx -s 'hello world' your@email.com
Checking the log to see if anything goes wrong
tail -f /var/log/mail.log

Troubleshooting

Must issue a STARTTLS command first.
You're missing smtp_use_tls = yes in main.cf.

No comments: