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
That worked, thank you very much!
LikeLike
you are welcome =)
LikeLike
i got this problem:–>postfix/postfix-script: fatal: the Postfix mail system is not running
LikeLike
which step u met this error? check if postfix is running, any error in /var/log/mail.log?
LikeLike
You are a savior! This is likely the 6th guide on setting up postfix I have read, and the only one that has done me any good.
LikeLike
Good to know that it could help =D
LikeLike
Worked perfectly for me, thank you. I had no experience setting up MTAs and tried a number of different tutorials with no success before I came across this one.
LikeLike
Glad to know that it works for you =D
LikeLike
Thank you! I struggled with sendmail and it was a waste of time.
LikeLike
you are welcome~ email configuration is really hard to be understood~
here just shows the basic usage but i still got many unknowns. =.=
anyway, good to know that i could help =D
LikeLike
Very Very Very thankful to you.
Finally i got my answer.
LikeLike
you are welcome =D
LikeLike
Works great, only one question to see if anyone solves.
How do I can not even bring up the gmail account?
shows the name of the account that postfix shipping, but the e-mail is Gmail.
regards
LikeLike
i think that could not be done since we are really using that gmail account to deliver the email.
see if other ppl could answer this question.
and thanks for your comment. =)
LikeLike
Exellent how-to
Many Thanks
LikeLike
You are welcome~ =)
LikeLike
Great tutorial. Only had one problem. I couldn’t complete the cat command. The error was: “/etc/postfix/cacert.pem: Permission denied”
I had to chmod the file to 666, and then I was able to complete the cat command. I did chmod it back to 644.
LikeLike
Ya, you may need to change the file permission if you dun have the root privilege.
Thanks for your reminder. =)
LikeLike
Nice, thanks. Was having exactly same issues, this works now. 🙂
LikeLike
Good to know that i could help. =)
LikeLike
Very nice and simple tutorial! You are so great! Thank you!
LikeLike
thanks for your comment. good to know that i could help. =D
LikeLike
arghh
i got a problem at the last moment…
the mail command tells me to either download mailutils or heirloom-mailx but apt-get doesn’t find any candidate version, aptitude doesn’t either.
any comment ?
LikeLike
of course found the solution right after asking…
aptitude install mailx
Tried that after looking into the dependencies needed when instaling with .deb package.
LikeLike
good to know that you solved the problem. =)
LikeLike
is it possible to use this to send root mail : like cron jobs ect to gmail if so how
LikeLike
Sorry, i couldn’t get what you mean. After you have setup the relay, you can send email using the mail command or php mail() function.
You can also use cron job the send email.
LikeLike
I was searching for a documentation of gmail configuration with postfix. I read many docs, but I could not done well. I tried this documentation and got result. Thank you again.
LikeLike
Good to know that this post could help. =D
LikeLike
I am a library professional from India. I shared your post in Koha (koha-community.org) discussion forum. Many librarians made use your solution to send notices from Koha library management system. I express my thanks in favor of library professionals.
LikeLike
That’s great. i would love to see this post could help more ppl.
Thanks a lot. =D
LikeLike
As many others have said, thank you so much for putting this up! Worked like a charm.
One question – right now when I get the email it shows that it’s from “root” (with the email address specified in sasl_passwd). What would I change to make that say something else like say, “Automated Server Message”?
LikeLike
Have you set a username in your gmail account? For the server i set, the email being sent will show the gmail user first name.
LikeLike
As said by postfix documentation http://www.postfix.org/postconf.5.html#smtp_use_tls, smtp_use_tls is deprecated, and smtp_tls_security_level shoudl be used instead. I had success with gmail while using:
LikeLike
Hello, on ubuntu 16.04 while configuring postfix for Koha Library management system, at this step,
cat /etc/ssl/certs/Equifax_Secure_CA.pem >> /etc/postfix/cacert.pem, it shows. cat: /etc/ssl/certs/Equifax_Secure_CA.pem: No such file or directory.
Is there anyway, to fix the issue and make postfix to send emails?
LikeLike
how to configure postfix on ubuntu 22.04 and latest version of koha 22.11
LikeLike