Setting up Sendmail to relay public SMTP server such as Gmail is quite difficult. In the past, i just kept looking for the blog posts in Google and found that people have different ways to setup Sendmail, but not all of them could be repeated successfully in my setup. After so many trials and errors, i made the relay works but i couldn’t fully understand what’s going on in the setup.
So this time, no more Sendmail, i would like to use Postfix instead.
System:
- OS: Ubuntu Lucid (Ubuntu 10.04)
1. Install the Postfix package. Select No configuration in the installation.
- apt-get install postfix
2. Copy the config file to /etc/postfix
- cp /usr/share/postfix/main.cf.debian /etc/postfix/main.cf
3. Install other required packages but they should be installed by default in Ubuntu Lucid.
- libsasl2-2
- libsasl2-modules
- ca-certificates
4. Append the following configuration to /etc/postfix/main.cf.
relayhost = [smtp.gmail.com]:587 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 smtp_use_tls = yes
5. Create the /etc/postfix/sasl_passwd.
[smtp.gmail.com]:587 <username>@gmail.com:<password>
6. Change the file permission of the /etc/postfix/sasl_passwd.
- chmod 400 /etc/postfix/sasl_passwd
7. Translate the /etc/postfix/sasl_passwd to Postfix lookup tables.
- postmap /etc/postfix/sasl_passwd
8. Create the /etc/aliases.db
- postalias hash:/etc/aliases
9. Create the /etc/postfix/cacert.pem.
- cat /etc/ssl/certs/Equifax_Secure_CA.pem >> /etc/postfix/cacert.pem
10. Restart Postfix.
- /etc/init.d/postfix restart
11. If you don’t have the mail command, install the mailutils package
- apt-get install mailutils
12. Send your first email with the our relay setting.
- mail -s “Hello World” <recipient’s email address>
Done =)
Reference: Relaying Postfix SMTP via smtp.gmail.com
Filed under: Linux, SMTP Tagged: Gmail, Linux, Postaday2011, Postfix, Sendmail, SMTP, Ubuntu
