Difference between revisions of "Gmail As Relay On Ubuntu"
Line 10: | Line 10: | ||
Install postfix and remove sendmail: <br> | Install postfix and remove sendmail: <br> | ||
− | {{Code|sudo apt-get -y install postfix mailutils | + | {{Code|sudo apt-get -y install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules |
sudo apt-get -y remove sendmail}} | sudo apt-get -y remove sendmail}} | ||
Line 16: | Line 16: | ||
Execute the following to update /etc/postfix/main.cf: | Execute the following to update /etc/postfix/main.cf: | ||
− | {{Code|sudo postconf -e 'relayhost<nowiki>=</nowiki> | + | {{Code|sudo postconf -e 'relayhost<nowiki>=</nowiki>[smtp.gmail.com]:587' |
sudo postconf -e 'smtp_sasl_auth_enable<nowiki>=</nowiki>yes' | sudo postconf -e 'smtp_sasl_auth_enable<nowiki>=</nowiki>yes' | ||
sudo postconf -e 'smtp_sasl_password_maps<nowiki>=</nowiki>hash:/etc/postfix/sasl_passwd' | sudo postconf -e 'smtp_sasl_password_maps<nowiki>=</nowiki>hash:/etc/postfix/sasl_passwd' | ||
− | sudo postconf -e 'smtp_sasl_security_options<nowiki>=</nowiki>'}} | + | sudo postconf -e 'smtp_sasl_security_options<nowiki>=</nowiki>noanonymous' |
+ | sudo postconf -e 'smtp_tls_CAfile<nowiki>=</nowiki>/etc/postfix/cacert.pem' | ||
+ | sudo postconf -e 'smtp_use_tls<nowiki>=</nowiki>yes'}} | ||
Create '''/etc/postfix/sasl_passwd''' file with your Gmail login credentials that looks like below: | Create '''/etc/postfix/sasl_passwd''' file with your Gmail login credentials that looks like below: | ||
− | {{Text|Text= | + | {{Text|Text=[smtp.gmail.com]:587 user.name@gmail.com:password}} |
Obviously, you need to change ''user'' to your username and ''password'' to your gmail password. <br> | Obviously, you need to change ''user'' to your username and ''password'' to your gmail password. <br> | ||
Line 32: | Line 34: | ||
{{Code|sudo chown root:root /etc/postfix/sasl_passwd | {{Code|sudo chown root:root /etc/postfix/sasl_passwd | ||
sudo chmod 600 /etc/postfix/sasl_passwd}} | sudo chmod 600 /etc/postfix/sasl_passwd}} | ||
+ | |||
+ | Validating the certificate: | ||
+ | {{Code|cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem <nowiki>|</nowiki> sudo tee -a /etc/postfix/cacert.pem}} | ||
Restart Postfix: | Restart Postfix: | ||
Line 45: | Line 50: | ||
− | Reference: [http:// | + | Reference: [http://yaui.me/postfix-gmail-smtp-server-relay-ubuntu Postfix + Gmail SMTP server relay in Ubuntu] |
Revision as of 02:38, 13 July 2012
tags: mail gmail ubuntu postfix relay
WARNING | |
---|---|
This is recommended only for advanced users, proceed with caution. |
This can be used to send mails from your HDA and to receive system emails.
To receive emails meant for the root user, you have to Forward System Emails after finishing this tutorial. Recommend you do not use copy and paste as there are hidden special characters that sometimes cause issues.
Install postfix and remove sendmail:
bash code |
---|
sudo apt-get -y install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules sudo apt-get -y remove sendmail
|
NOTE: During install of postfix, a popup box may display. If it does, select OK and then Internet. Add your domain name (i.e. home.com) and then select OK.
Execute the following to update /etc/postfix/main.cf:
bash code |
---|
sudo postconf -e 'relayhost=[smtp.gmail.com]:587' sudo postconf -e 'smtp_sasl_auth_enable=yes' sudo postconf -e 'smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd' sudo postconf -e 'smtp_sasl_security_options=noanonymous' sudo postconf -e 'smtp_tls_CAfile=/etc/postfix/cacert.pem' sudo postconf -e 'smtp_use_tls=yes'
|
Create /etc/postfix/sasl_passwd file with your Gmail login credentials that looks like below:
Text |
---|
[smtp.gmail.com]:587 user.name@gmail.com:password
|
Obviously, you need to change user to your username and password to your gmail password.
Create the password database:
bash code |
---|
sudo postmap hash:/etc/postfix/sasl_passwd
|
Protect the files with your Gmail login data:
bash code |
---|
sudo chown root:root /etc/postfix/sasl_passwd sudo chmod 600 /etc/postfix/sasl_passwd
|
Validating the certificate:
bash code |
---|
cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | sudo tee -a /etc/postfix/cacert.pem
|
Restart Postfix:
bash code |
---|
sudo /etc/init.d/postfix restart
|
Now try sending a mail, it should reach your Gmail account (change user to match your account name):
bash code |
---|
echo "This is Content" | sudo mail -s "This is subject" user@gmail.com
|
Check the mail log:
bash code |
---|
tail -f /var/log/mail.log
|
If all goes well, you should not see any errors. When you check your account, it is possible the email will appear as SPAM. Be sure to check that folder for it.
Reference: Postfix + Gmail SMTP server relay in Ubuntu