FeaturesWP CloudPricingEE CLIContactMy Account

Features

Team Access & User Permissions

Server Setup & Management

Site Creation & Management

Deployments & Developer Tools

Firewall Protection

Speed & Caching

Backups & Recovery

Logs & Monitoring

Create WP Cloud Sites

All Features

Read Documentation

Install

Installation Guide

FAQ

Roadmap

Explore EE CLI

Resources

Commands

Handbook

Blog

Community

Forum

EasyExperts

Tutorials

Subscribe

Github

CLEAR

Start For Free

separator Tutorials separator Linux separator Configure Postfix to Use Gmail SMTP on Ubuntu

Topics

On this page

Relaying Postfix mails via smtp.gmail.com:

Testing

Check if mails are sent via Gmail SMTP server

Troubleshooting

Configure Postfix to Use Gmail SMTP on Ubuntu

Update: This article is part of WordPress-Nginx tutorials series.

If you want to use a Gmail account as a free SMTP server on your Ubuntu-Linux server, you will find this article useful. This guide is tested with Ubuntu 12.04. If you face any issue, feel free to use comments-section below.

Relaying Postfix mails via smtp.gmail.com:

First, install all necessary packages:


			sudo apt-get install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules
		

If you do not have postfix installed before, postfix configuration wizard will ask you some questions. Just select your server as Internet Site and for FQDN use something like mail.example.com

Then open your postfix config file:


			vim /etc/postfix/main.cf
		

and following lines to it:


			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
		

You might have noticed that we haven’t specified our Gmail username and password in above lines. They will go into a different file. Open/Create


			vim /etc/postfix/sasl_passwd
		

And add following line:


			[smtp.gmail.com]:587    USERNAME@gmail.com:PASSWORD
		

If you want to use your Google App’s domain, please replace @gmail.com with your @domain.com

Fix permission and update postfix config to use sasl_passwd file:


			sudo chmod 400 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd
		

Next, validate certificates to avoid running into error. Just run following command:


			cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | sudo tee -a /etc/postfix/cacert.pem
		

Note: If you run into issues with above command, try changing certificate name to thawte_Primary_Root_CA.pem in above command. Thanks Alexander Bakker for the note.

Finally, reload postfix config for changes to take effect:


			sudo /etc/init.d/postfix reload
		

Testing

Check if mails are sent via Gmail SMTP server

If you have configured everything correctly, following command should generate a test mail from your server to your mailbox.


			echo "Test mail from postfix" | mail -s "Test Postfix" you@example.com
		

To further verify, if mail sent from above command is actually sent via Gmail’s SMTP server, you can log into Gmail account USERNAME@gmail.com with PASSWORD and check “Sent Mail” folder in that Gmail account. By default, Gmail always keeps a copy of mail being sent through its web-interface as well as SMTP server. This logging is one strong reason that we often use Gmail when mail delivery is critical.

Once configured, all emails from your server will be sent via Gmail. This method will be useful if you have many sites on your server and want them all to send emails via Gmail’s SMTP server.

Alternatively, you can use a plugin like WP Mail SMTP so that mails from your particular WordPress site will be sent using Gmail’s SMTP server.

Please note that Gmail’s SMTP server has a limit of 500 emails per day. So use wisely! 🙂

Troubleshooting

Error: “SASL authentication failed; server smtp.gmail.com”

You need to unlock the captcha by visiting this page https://www.google.com/accounts/DisplayUnlockCaptcha

You can run test again after unlocking captcha.

P.S. Do not miss out on our other helpful tutorials. Join us on twitter and facebook for more updates.

 

Using openssl to match private key, cerificate and CSR

PREVIOUS

Logrotate Example for Custom Logs

NEXT


Comments

  1. elricho Avatar

    elricho

    February 26, 2013

    Excelent tutorial it work very well !!! Thank you so much.

    1. Rahul Bansal Avatar

      Rahul Bansal

      February 26, 2013

      Glad to know that you find it useful. 🙂

    2. Pundlik Avatar

      Pundlik

      December 5, 2013

      This is not work properly in my UBUNTu 12.04
      Can u help me…..

      1. Rahul Bansal Avatar

        Rahul Bansal

        December 6, 2013

        For help, please check http://rtcamp.com/tutorials/mail/postfix-debugging/ first.

        If you notice anything in postfix logs, you can create a support request in our free forums – https://rtcamp.com/support/forum/wordpress-nginx/

  2. Mark Avatar

    Mark

    March 22, 2013

    A great big thank you to you this worked brilliantly on my Ubuntu 12.04.2 LTS install

  3. birdpunisher Avatar

    birdpunisher

    April 1, 2013

    I felt the need to say thank you since you were a big help – straightforward explanation that worked after the first try 🙂

  4. Zeeshan Avatar

    Zeeshan

    April 22, 2013

    Excellent.. Thanks for saving time.

  5. kasun Avatar

    kasun

    May 2, 2013

    Man ! I owe you big time 😀 thanks heaps , This is a lot simple and understandabale than any other thing I’ve found , It actually works ! KEEP UP THE GOOD WORK ! CHEERS !!!

  6. Chris Walsh Avatar

    Chris Walsh

    May 9, 2013

    This was fantastically useful; thanks for taking the time to write it up.

  7. ayad Avatar

    ayad

    May 21, 2013

    Excellent..thanks

    1. momo Avatar

      momo

      May 23, 2013

      It is excellent.

  8. Ricardo Avatar

    Ricardo

    May 25, 2013

    After configured everything and download the root cert from Thawte I am receiving the following error. Could you please help me?

    Action: failed
    Status: 5.7.0
    Remote-MTA: dns; smtp.gmail.com
    Diagnostic-Code: smtp; 530 5.7.0 Must issue a STARTTLS command first.
    f71sm25739776yha.8 – gsmtp

    1. Rahul Bansal Avatar

      Rahul Bansal

      June 2, 2013

      It looks related to postfix main.cf file.

      Check settings in `/etc/postfix/main.cf`. Have you modified any setting?

    2. JEsus Avatar

      JEsus

      September 13, 2013

      USE THIS in the main.cf

      eliminates default security options which are imcompatible with gmail

      smtp_sasl_security_options =

      1. Jens Skov Avatar

        Jens Skov

        January 31, 2014

        I also have this problem.

        I can’t spot the error.. Any suggestions?

        My main.cf looks like:

        myhostname = raspberrypi alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases myorigin = /etc/mailname mydestination = raspberrypi, localhost.localdomain, localhost relayhost = [smtp.gmail.com]:587 mynetworks = 127.0.0.0/8 mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = all inet_protocols = ipv4

        smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU) biff = no # appending .domain is the MUA's job. append_dot_mydomain = no # Uncomment the next line to generate "delayed mail" warnings #delay_warning_time = 4h readme_directory = no # TLS parameters smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key smtpd_use_tls=yes smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache # use sasl when authenticating to foreign SMTP servers smtp_sasl_auth_enable = yes # path to password map file smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd # list of CAs to trust when verifying server certificate smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

        # eliminates default security options which are imcompatible with gmail smtp_sasl_security_options =

        1. Jens Skov Avatar

          Jens Skov

          January 31, 2014

          Ah, I found the answer here:
          http://askubuntu.com/questions/228938/how-can-i-configure-postfix-to-send-all-email-through-my-gmail-account

  9. Bastian Avatar

    Bastian

    May 26, 2013

    Anyone else facing an ‘Authenication Required’ error message when sticking to the tutorial (although setting up the password file worked flawlessly)?

    1. Rahul Bansal Avatar

      Rahul Bansal

      June 2, 2013

      @Bastian

      Do you have 2-factor authentication enabled for your Gmail? You may need to use application specific password.

      1. Bastian Avatar

        Bastian

        June 2, 2013

        @Rahul

        Never mind. I solved the problem by fixing the typos that I had previously added to the password and configuration files (by accident) :-).

        1. Rahul Bansal Avatar

          Rahul Bansal

          June 2, 2013

          Glad to know that. Thanks for updating. 🙂

  10. Ed Avatar

    Ed

    May 29, 2013

    Worked Perfectly! Thanks!

  11. Omar Avatar

    Omar

    June 24, 2013

    AWESOME! THANKS!

  12. Kinshuk Tyagi Avatar

    Kinshuk Tyagi

    June 28, 2013

    Thanks it worked!

  13. Yuri Sklar Avatar

    Yuri Sklar

    June 30, 2013

    Thanks a lot!

  14. kk Avatar

    kk

    July 6, 2013

    worked great….

  15. didnot work Avatar

    didnot work

    July 9, 2013

    XXXx@XXXXXX:/etc/postfix$ echo “Test mail from postfix” | mail -s “Test Postfix” XXXXX@XXX.com
    The program ‘mail’ is currently not installed. To run ‘mail’ please ask your administrator to install the package ‘mailutils’

    1. Rahul Bansal Avatar

      Rahul Bansal

      July 9, 2013

      You need to install mailutils package.

  16. Rafael Avatar

    Rafael

    July 9, 2013

    It is not the first tutorial that i tried, but it is the first that worked on my Ubuntu 12.04.
    It is excellent. Thank you very much

  17. rossdavidh Avatar

    rossdavidh

    July 13, 2013

    Worked great! However, in my case I had to do one more thing which I thought I’d share here. After sending the test email, I got a “Suspicious sign-in prevented” email from google in my inbox. So, I went to google.com to search for a solution, saw a big red banner saying something like “someone tried to login to your email from a new application, was it you?” I clicked through several screens to say “yes, this was me”.

    echo “Test mail from postfix” | mail -s “Test Postfix” me@mydomain.com

    …and this time got test email in gmail account!

    Just sharing this in case someone else gets this.

    1. Rahul Bansal Avatar

      Rahul Bansal

      July 13, 2013

      Thanks for sharing your experience. Might help somebody.

      Once accessing Gmail via IMAP, I got message on my terminal asking me to complete CAPTCHA from browser by opening link – https://accounts.google.com/UnlockCaptcha

      Google might have more security checks like these in-place!

      1. Gregory Avatar

        Gregory

        February 18, 2014

        Oh my goodness!… I tried everything and couldn’t get SASL Authentication working. I knew I was close. Google even warned me of the “Suspicious Activity” which I confirmed, but then I saw the link you posted:

        https://accounts.google.com/UnlockCaptcha

        Boom!… it worked.

  18. krishna Avatar

    krishna

    July 16, 2013

    very nice smtp relay worked like charm.thanks dude.

  19. Vamsi Ampolu Avatar

    Vamsi Ampolu

    July 17, 2013

    When executing the following command:

    postfix/postfix-script: fatal: the Postfix mail system is not running
    [fail]

    1. Rahul Bansal Avatar

      Rahul Bansal

      October 14, 2013

      Which command you tried executing?

      Sorry but looks like your command got stripped during comment submission.

  20. Vamsi Ampolu Avatar

    Vamsi Ampolu

    July 17, 2013

    sudo /etc/init.d/postfix reload
    * Reloading Postfix configuration… postfix/postfix-script: fatal: the Postfix mail system is not running
    [fail]

    1. Rahul Bansal Avatar

      Rahul Bansal

      July 18, 2013

      Just try… `sudo /etc/init.d/postfix restart`

      If you get error `bind 0.0.0.0 port 25: Address already in use` then it might be the case some other mail program is already present in your system.

  21. subin Avatar

    subin

    July 28, 2013

    Hi,
    I configured postfix as above, but unfortunately send mail root through root@ not from gmail , and no email at send mail of gmail a/c, I double checked all config exactly as per this doc, Can you please help me , Is their any additional configuration I need set up?

    -Subin

    1. Rahul Bansal Avatar

      Rahul Bansal

      August 14, 2013

      If gmail is configured correctly, FROM address will be overridden with Gmail’s email address for all outgoing email.

      It looks like your emails aren’t sent by Gmail. Hence they are not appearing in Gmail’s sent mail folder as well.

      1. Herm Avatar

        Herm

        September 11, 2013

        Hi subin

        Did you get a resolution to your issue? I’m facing the same. The FROM address is not being overridden. So it is trying to send from “linuxuser”@gmail.com instead of “gmailname”@gmail.com

        1. Rahul Bansal Avatar

          Rahul Bansal

          October 14, 2013

          This is really strange as Gmail makes sure that we can not override FROM name on the go.

          In fact, that is one reason to NOT use Gmail in many production server where system need to send emails from multiple FROM addresses.

  22. Scor Avatar

    Scor

    July 30, 2013

    Great guide, could set up relaying in 5 minutes. 🙂 Thanks!

    1. Rahul Bansal Avatar

      Rahul Bansal

      August 14, 2013

      Glad to know that. 🙂

  23. Matache Avatar

    Matache

    August 8, 2013

    I have a problem, everything worked without a problem , no errors no nothing, but when i check my gmail account nothing was sent? What do you think the problem might be?

    1. Rahul Bansal Avatar

      Rahul Bansal

      August 8, 2013

      Please check http://rtcamp.com/wordpress-nginx/tutorials/postfix/debugging/

      You may find some details in postfix logs.

      Also – did receiver receive test email?

      1. Matache Mihai Avatar

        Matache Mihai

        August 15, 2013

        Thanks for the promp response and sorry for the late comeback, but I found out that at the place where i was trying to set this up smtp is a no no, it has been disabled on the network for security reasons.

        1. Rahul Bansal Avatar

          Rahul Bansal

          August 16, 2013

          That’s something strange! Outbound mail disabled for security reason. 😐

          1. Matache Mihai Avatar

            Matache Mihai

            August 16, 2013

            Not all outbound mail. 99% of the users use windows and have outlook configured through the company servers. I’m the oddball there because i’m trying to get a backup application running on a linux pc for some of the older computers that can’t be replaced for some reason or another, and when i say old i mean going on 20 years, they’re practicaly the legal drinking age. I was trying to configure email client on that. Thanks for all the help.

  24. anirudha rath Avatar

    anirudha rath

    August 14, 2013

    after configuring postfix as above I cann’t receive any mail from the server to my mail id

    1. Rahul Bansal Avatar

      Rahul Bansal

      August 14, 2013

      Please check http://rtcamp.com/wordpress-nginx/tutorials/postfix/debugging/

      If you not getting anything it may be because postfix is not running.

  25. Subin Avatar

    Subin

    August 16, 2013

    Hi Rahul, Its a great post, helpful for me, The issue I posted earlier is resolved, By default sendmail also installed and sending mail through sendmail, I removed sendmail, now everything is as expected. Thank you somuch

    -Subin

    1. Rahul Bansal Avatar

      Rahul Bansal

      August 26, 2013

      Glad to know your problems fixed. 🙂

  26. krishna Avatar

    krishna

    August 22, 2013

    I have strange problem please help me

    it was all working fine,

    now i cannot send email to gmail.com,yahoo.co.in,

    but i can send to hotmail and google hosted email service,rediffpro account.

    i cant understand what is this problem please help….

    1. Rahul Bansal Avatar

      Rahul Bansal

      August 26, 2013

      Look for postfix logs and also Gmail’s sent folder for email address being used.

      On other end, check spam folder on email accounts where you are not receiving mails.

  27. Chris Brown Avatar

    Chris Brown

    September 12, 2013

    Thank you! This article just saved me a loooong weekend of work.

  28. Praveen Avatar

    Praveen

    September 20, 2013

    a Big thanks for the point shoot instructions. It worked pretty well. Now I will try to configure my other domain SMTP here (you showed it how 🙂 )….

  29. Mike Avatar

    Mike

    September 20, 2013

    Just wanted to extend my thanks to you for this succinct write-up. I have setup mail on Ubuntu servers before, but this was my first time attempting SMTP via Postfix, and this was a very simple and quick mail setup that just works.

    Nicely done!

    1. Rahul Bansal Avatar

      Rahul Bansal

      September 23, 2013

      Thanks for really encouraging comment 🙂

  30. Ubuntu User Avatar

    Ubuntu User

    September 20, 2013

    Thank you. Works for me. Also liked the simple instructions.

  31. postfix-r Avatar

    postfix-r

    September 22, 2013

    Works Great!! thanks a lot for the well documented steps.

    Found “aptitude” command does’t work on Ubuntu 13.04 ( 13.04, Raring Ringtail ) ,
    – Used insted “apt-get ”

    sudo aptitude install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules

    WORKS great!, Thank you.

    1. Rahul Bansal Avatar

      Rahul Bansal

      September 23, 2013

      I prefer apt-get only. Updated article so I won’t run into issues on Ubuntu 13.04

      Thanks for your feedback.

  32. RavanH Avatar

    RavanH

    September 29, 2013

    Why not switch to msmtp instead of postfix if you’re only going to use it for sending through gmail? I’ve not compared/tested but I think its memory footprint is much smaller… While setup is similar 🙂

    1. Rahul Bansal Avatar

      Rahul Bansal

      October 14, 2013

      I haven’t used msmtp before. I am using postfix from 2008 (when I started getting into this stuff).

      I only look for alternative when I am not happy with current packages. Plus I need postfix for typical mail-hosting servers and elsewhere.

      If you try msmtp and find it good, please share your findings. I am always up for simplicity as long as it doesn’t compromise functionality.

      1. RavanH Avatar

        RavanH

        October 15, 2013

        One very short tutorial here http://www.absolutelytech.com/2010/07/17/howto-configure-msmtp-to-work-with-gmail-on-linux/ (for Ubuntu Desktop so replace gedit with nano or vim or any other CL editor of preference) 🙂

  33. suraj Avatar

    suraj

    October 5, 2013

    postdrop: warning: unable to look up public/pickup: No such file or directory

    1. Rahul Bansal Avatar

      Rahul Bansal

      October 14, 2013

      Looks like you have sendmail installed as per this guide.

  34. alex.fliker Avatar

    alex.fliker

    October 7, 2013

    Thank you so much!

  35. Aanu Avatar

    Aanu

    November 3, 2013

    Hey man,
    You’re really the best… I’ve been on this for over a week but U did it in less than 30 minutes!!! Thanks a million. I hope I will be able to send with attachments too!!!
    Thany you so much… You deserve the best

    1. Rahul Bansal Avatar

      Rahul Bansal

      November 5, 2013

      Thanks aanu for your appreciation.

  36. Alex Lydiate Avatar

    Alex Lydiate

    November 7, 2013

    Beautiful! You’re a hero of modern times, my friend, what a superb tutorial. I shall now send emails from the command line alone, simply because I can 🙂

  37. André Kjellstrup Avatar

    André Kjellstrup

    November 8, 2013

    Thank you.
    Unfortunately I get this:
    Nov 8 12:27:41 ODIN2 postfix/error[20109]: EDB1E77006EE: to=, orig_to=, relay=none, delay=0, delays=0/0/0/0, dsn=5.0.0, status=bounced ([smtp.gmail.com]:587)

    I have ssmtp on my server, but cron did not like to use it. I assume it’s not the cause of this problem.
    also: I use 2-factor auth, but I gave it an application-specific password. – and it does not seem to be an authentication problem.
    Please help me. 🙂

    1. André K. Avatar

      André K.

      November 8, 2013

      Also, I did not get a wizard, you mention that I should configure as “internet site”.
      I changed
      myhostname ODIN2.example.com

      now the error is still the same, except for the destination address being all wrong
      Nov 8 12:54:12 ODIN2 postfix/error[25061]: 871077700701: to=, relay=none, delay=0, delays=0/0/0/0, dsn=5.0.0, status=bounced (odin2.example.com)

      ow can I do this” select Internet Site and for FQDN use something like mail.example.com”

      1. Rahul Bansal Avatar

        Rahul Bansal

        November 11, 2013

        Please use support forum – https://rtcamp.com/support/forum/wordpress-nginx/

        Attach output of “postconf -n” command and your error log.

        1. André K. Avatar

          André K.

          November 12, 2013

          Purged ssmtp, and postfix, then reinstalled postfix , instant success.
          Thank you.

  38. Tamara Avatar

    Tamara

    November 11, 2013

    Hi Rahul,

    This tutorial has been very helpful many times. However, I am stuck with a couple of clients using Zoho (at my recommendation as it is free-er)

    Do you have any experience setting up postfix with Zoho? If you do, would you be willing to write another lovely tutorial?
    The internet has failed me and I was not able to find anything but the following:
    https://forums.zoho.com/topic/setup-postfix

    Thanks for your time,
    Tamara

    1. Rahul Bansal Avatar

      Rahul Bansal

      November 11, 2013

      I never used Zoho mail. But if they are providing SMTP interface then you can just substitute values for Zoho SMTP in place of Gmail SMTP to get it working.

      All this tutorial does in relay outgoing emails via Gmail’s SMTP server rather than local sendmail program.

      1. Tamara Avatar

        Tamara

        November 11, 2013

        Thank you for the prompt response!

        Zoho uses an SSL connection rather than TLS. I’ve started playing with the config outlined at the following article http://major.io/2007/07/01/enable-ssl-support-in-postfix/, but got stuck on how to add the username and password.

        Would you know if I’d still be able to use the following for storing the username and pass

        smtp_sasl_auth_enable = yes
        smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
        smtp_sasl_security_options = no anonymous

        Thanks again 😀

        1. Rahul Bansal Avatar

          Rahul Bansal

          November 11, 2013

          Those settings comes into picture when “your postfix server” is used by other applications. In this case, you are using “zoho server” so I don’t think your postfix’s master conf will matter much.

          Try replacing [smtp.gmail.com]:587 with [smtp.zoho.com]:465 evrywhere in this article.

          1. Wei Fang Avatar

            Wei Fang

            December 13, 2013

            Replacing with [smtp.zoho.com]:465 in main.cf unfortunately doesn’t help, since Postfix doesn’t support legacy TLS. I happened to get Postfix work with Zoho email while setting up gitlab. Details are here. Details Link.

  39. ayush Avatar

    ayush

    November 14, 2013

    thank you sir…

  40. YoTsumi Avatar

    YoTsumi

    November 14, 2013

    Works perfect 🙂 Thank !

  41. pkinjo Avatar

    pkinjo

    November 15, 2013

    After issuing command:
    sudo chmod 400 /etc/postfix/sasl_passwd

    Come with this issue:
    sudo: unable to resolve host mail

    Masters, need some help please. Thanks a lot.

    1. Rahul Bansal Avatar

      Rahul Bansal

      November 16, 2013

      Can you check postfix logs for more detailed error messages?

      Try – http://rtcamp.com/tutorials/mail/postfix-debugging/

  42. George Avatar

    George

    November 16, 2013

    Thank you. It’s pity I didn’t find this article earlier…

  43. Mohammed Awwal Avatar

    Mohammed Awwal

    November 17, 2013

    works like a freaking charm…… whoever did this tutorial he freaking rock….thanks wherever you are

  44. Ian C Avatar

    Ian C

    November 23, 2013

    Thank you very much for this excellent tutorial. It works fine on Ubuntu 12.04 LTS but not on 13.10

    1. Rahul Bansal Avatar

      Rahul Bansal

      November 24, 2013

      We only use LTS releases for Ubuntu.

      However, if you manage to get this working on Ubuntu 13.10, feel free to suggest changes and I will have this post updated with your contribution.

  45. B.k.Jayasundera Avatar

    B.k.Jayasundera

    November 26, 2013

    Thank you Rahul

  46. erikb85 Avatar

    erikb85

    November 28, 2013

    And how to debug if the testrun fails? As far as I can tell it doesn’t even say any error messages or warnings.

    1. Rahul Bansal Avatar

      Rahul Bansal

      November 28, 2013

      Check postfix error log.

      This might help you – http://rtcamp.com/tutorials/mail/postfix-debugging/

  47. Paula Avatar

    Paula

    December 7, 2013

    Worked! Thanks.

  48. Raja Avatar

    Raja

    December 18, 2013

    Dear, excellent posting, followed step by step and working like a charm.
    All the best! Regards raja

  49. angels1100 Avatar

    angels1100

    December 19, 2013

    Dec 19 12:11:42 user-System-Product-Name postfix/smtp[20581]: B3DA31A421D2: SASL authentication failed; server smtp.gmail.com[74.125.143.109] said: 535-5.7.8 Username and Password not accepted. Learn more at?535 5.7.8 http://support.google.com/mail/bin/answer.py?answer=14257 y11sm1790904lbm.13 – gsmtp
    Dec 19 12:11:43 user-System-Product-Name postfix/smtp[20581]: B3DA31A421D2: SASL authentication failed; server smtp.gmail.com[74.125.143.108] said: 535-5.7.8 Username and Password not accepted. Learn more at?535 5.7.8 http://support.google.com/mail/bin/answer.py?answer=14257 mq10sm1794674lbb.12 – gsmtp
    Dec 19 12:11:43 user-System-Product-Name postfix/smtp[20581]: connect to smtp.gmail.com[2a00:1450:4008:c01::6d]:587: Network is unreachable
    Dec 19 12:11:43 user-System-Product-Name postfix/smtp[20581]: B3DA31A421D2: to=, relay=none, delay=2.2, delays=0.08/0/2.2/0, dsn=4.4.1, status=deferred (connect to smtp.gmail.com[2a00:1450:4008:c01::6d]:587: Network is unreachable)

    1. Rahul Bansal Avatar

      Rahul Bansal

      December 20, 2013

      Look slike your server couldn’t talk to smtp.gmail.com.

      Try checking network connectivity issue.

  50. Ping Avatar

    Ping

    December 26, 2013

    Worked on Ubuntu 12.04
    Thank you a lot! I spent like 4 days with sendmail, postfix, dns server set up. So fed up with all these tech challenges. Finally reinstall Ubunut and you post saved me!

  51. Asdrubal Velasquez Avatar

    Asdrubal Velasquez

    December 30, 2013

    Worked!! (tested on Lubuntu 13.10)
    Best regards

    1. Rahul Bansal Avatar

      Rahul Bansal

      December 30, 2013

      Thanks for confirming. 🙂

  52. Dennis van den Berg Avatar

    Dennis van den Berg

    January 5, 2014

    Great instructions, thanks!

  53. Enis Avatar

    Enis

    January 7, 2014

    Great tutorial, thank you!

  54. reena Avatar

    reena

    January 8, 2014

    Hi, thanks for your guide. I got it to work for outgoing emails from root@localhost. What must i do to get it to work for incoming emails sent to gmail? I tried searching on the internet but came up with nothing :(. Hopefully you have a solution for me.

  55. reena Avatar

    reena

    January 8, 2014

    sorry there is a typo above, i mean incoming emails sent to root. not gmail. thanks again!

    1. Rahul Bansal Avatar

      Rahul Bansal

      January 8, 2014

      Sorry I couldn’t understood your problem clearly. This article deals with outgoing mails only.

      Your server cannot receive incoming emails for root@localhost from outside world. Incoming mail is whole different topic.

      If you are concerned about “replies” to mails going through Gmail; those “replies” will be directly reach to Gmail server.

  56. Darren Avatar

    Darren

    January 15, 2014

    Fantastic tutorial but I’m falling at the first hurdle;-
    Reading packages lists…Done
    Building dependency tree
    Reading state information… Done
    Package mailutils is not available, but is referred to by another package.
    This may mean that the package is missing, has been obsoleted, or is only available from another source
    E: Package ‘mailutils’ has no installation candidate
    E: Unable to locate package libsas12-2
    E: Unable to locate package libsas12-modules

    1. Darren Avatar

      Darren

      January 15, 2014

      Sorry folks, I hadn’t configured the network properly.

      1. Rahul Bansal Avatar

        Rahul Bansal

        January 15, 2014

        Glad to know you manage to solve your issue yourself. 🙂

        1. Darren Avatar

          Darren

          January 16, 2014

          This is a fantastic tutorial!!!!

  57. anonymous Avatar

    anonymous

    January 16, 2014

    I did what you said but when i check Sentmail, the mail is not there…the resident also did not recieve any mail.pls help.i m using uunty 12.04 lts.Thank you.

    1. Rahul Bansal Avatar

      Rahul Bansal

      January 16, 2014

      Did u try – https://rtcamp.com/tutorials/mail/postfix-debugging/ ?

  58. anonymous Avatar

    anonymous

    January 17, 2014

    i m getting mail in mailbox but no mail in sent mail in my gmail account.my host name is my computer name without domain and i m not able to change it by editing /etc/hostname.

    1. Rahul Bansal Avatar

      Rahul Bansal

      January 17, 2014

      This means mails are sent via localhost and not gmail.

      Try this – https://rtcamp.com/tutorials/mail/fqdn-reverse-dns-ptr-mx-record-checks/

      1. anonymous Avatar

        anonymous

        January 17, 2014

        changed my host name by editing /etc/hostname and /etc/hosts but now host myfqdn is not working and giving 3(NXDomain) error.Still the mail is sent via my fqdn and not gmail.

        1. Rahul Bansal Avatar

          Rahul Bansal

          January 18, 2014

          Did you follow instructions in above article? Hostname doesn’t play much role in relaying outgoing mails via Gmail.

      2. anonymous Avatar

        anonymous

        January 18, 2014

        Reverse Dns not working in my fqdn.its giving 3(NXDomain)error.i enabled smtp my gmail account whose details i saved in/etc/postfix/sasl_passwd so whenever i send to any other gmail account via command prom then its working but if i send it to username@myfqdn then its not sent via gmail accnt .i m not able to send any mail to my fqdn.for example if fqdn is myhost.mail.com then i can send mail to username@myhost.mail.com but not to myhost.mail.com.when i try to send mail to myhost.mail.com then it gives failure report in my gmail account…if my hostname is myhost and fqdn is myhost.mail.com then sending mail to abc@mail.com is giving failure report but abc@myhost.mail.com is sending mail bt not via gmail.

        1. Rahul Bansal Avatar

          Rahul Bansal

          January 22, 2014

          I think you are having problem for sending to only one particular domains – your FQDN in this case.

          Check postfix value for mydestination setting. If its anything apart from localhost, or contains your FQDN, then remove that value from there.

  59. Pritam Avatar

    Pritam

    January 20, 2014

    Thank you Rahul. It worked like charm. Your article saved a lot of time for me.

  60. anonymous Avatar

    anonymous

    January 21, 2014

    Is there any way of sending email from gmail to my domain??

    1. Rahul Bansal Avatar

      Rahul Bansal

      January 22, 2014

      Not sure what are you asking for? All mails will be through Gmail account’s email address. You can use an email address with Google Apps mail.

  61. néo Avatar

    néo

    January 22, 2014

    Hello sir, thank you for your great tutorials, i know this is not the right place for this but unfortunely im a windows user with xampp server, i configured my php.ini and my sendmail.ini for gmail smtp, my php mail sender script says mail successfully sent, but i dont recive any thing, i tried all possible sollutions on internet but still got this problem! so maybe you cn helep me 🙁 PLEAZEEE!

    1. Rahul Bansal Avatar

      Rahul Bansal

      January 22, 2014

      Sorry. Haven’t touched a Windows machine in last 5 years so can’t help with that!

  62. Piers Harding Avatar

    Piers Harding

    January 22, 2014

    Brilliant!

  63. Jim Volf Avatar

    Jim Volf

    January 27, 2014

    Awesome. Worked great. Thank you very much!

  64. Raseel Bhagat Avatar

    Raseel Bhagat

    January 27, 2014

    Thanks a lot Rahul for such a precise, concise post. It served me really well and saved up a LOT of time to do a quick mail test.

  65. Trisha Avatar

    Trisha

    January 30, 2014

    Thank you for this tutorial! I got my gmail smtp on postfix to work, Quick question which I really pray u have an answer for it! How do I configure fail2ban for postfix if I followed your tutorial? thank you!!!

    1. Rahul Bansal Avatar

      Rahul Bansal

      February 3, 2014

      How do I configure fail2ban for postfix if I followed your tutorial?

      The same way you would have configured when not using Gmail as reply in postfix. I guess fail2ban comes into picture if you are running a public SMTP server. In this case, it is assumed that postfix is not accessible to the outside world via SMTP.

      Gmail accounts has very low sending limits. So we use this kind of setup only in small apps for notification email types only.

  66. Ghost Avatar

    Ghost

    February 1, 2014

    Awesome, awesome, awesome! Thanx a lot for this, works like a charm 🙂

  67. Aka Chilala Avatar

    Aka Chilala

    February 2, 2014

    Much appreciated, Rahul. This worked perfectly.

  68. Robert Reid Avatar

    Robert Reid

    February 3, 2014

    Thank you!

  69. tanvir.raihn Avatar

    tanvir.raihn

    February 3, 2014

    Many , thanks.. its working and u awesome 🙂

  70. lizhi Avatar

    lizhi

    February 4, 2014

    my postfix can send an e-mail ,but the sender is wrong. My configuration is pool@ftc-c.com, but that e-mail is from=www-data@pool.ftc-c.com.

    postfix/qmgr[22022]: 1225BA0CF5: from=www-data@pool.ftc-c.com, size=1030, nrcpt=1 (queue active)
    how do I change the ‘from’?

    1. Rahul Bansal Avatar

      Rahul Bansal

      February 5, 2014

      Looks like pool.ftc-c.com is your hostname and mails are sent from postfix only. Are you sure you have configured Gmail setup properly?

      Because all mails replayed from Gmail uses Gmail’s email address as FROM address.

  71. sayantani Saha Avatar

    sayantani Saha

    February 6, 2014

    Hi, I follow your instruction to send mail via gmail using postfix. However, my network is working behind proxy with userid and password. Will you help me setting up these parameters so that I also feel happy to send mail using this way.

    1. Rahul Bansal Avatar

      Rahul Bansal

      February 6, 2014

      Sorry. I never configured anything like that. Most likely you need to do this outside postfix. Not sure though.

  72. vins069 Avatar

    vins069

    February 7, 2014

    very good, simple and efficient, thanks so much

  73. Ranjit Avatar

    Ranjit

    February 10, 2014

    Thank you….clear and concise instructions…..worked in first attempt.!!

  74. BuzB Avatar

    BuzB

    February 17, 2014

    Excellent instructions, thank you!

  75. Rafael Avatar

    Rafael

    February 19, 2014

    Excellent article. Thank you by to share your knowledge.
    Hugs!

  76. Randy Avatar

    Randy

    February 22, 2014

    Thank you very much, this tutorial was spot on, and very easy to follow. And as an added bonus it worked like a peach! You Rock, Rahul, thanks.

  77. Joe Avatar

    Joe

    February 26, 2014

    when I am at work where we have a domain it works fine, when I am at home it complains about fqdn and won’t send, what can I do to make it work at home where I don’t have a domain?

    1. Rahul Bansal Avatar

      Rahul Bansal

      February 26, 2014

      Postfix via Gmail shouldn’t care about domain or IP. This is used mostly in locations where server/machine IP is dynamic.

      I am assuming that you have a postfix+gmail setup on your laptop which is you are using at home/work.

      When at work try ping yourdomain.name. Repeat same commands at home. If there is a difference in IP, try to offset that difference by modifying local /etc/hosts.

      Another case, is postfix+gmail setup is present at work machine but postfix has smtpd_recipient_restrictions enabled with setting reject_non_fqdn_sender. Remove reject_non_fqdn_sender so your (senders) IP/FQDN will not be verified.

      References: http://www.postfix.org/postconf.5.html#smtpd_sender_restrictions and http://www.akadia.com/services/postfix_uce.html

  78. Daniel Clarks Avatar

    Daniel Clarks

    February 27, 2014

    Work’d for me, tanks

  79. si Avatar

    si

    February 27, 2014

    brilliant!!!

  80. Daniel Stoian Avatar

    Daniel Stoian

    February 28, 2014

    Your tutorial worked very well on Debian 7 (Wheezy).<br/>
    Clear steps that anyone can understand.<br/>
    Thank you very much!

    1. Rahul Bansal Avatar

      Rahul Bansal

      February 28, 2014

      Glad to know this. 🙂

      Never tested this before on Debian.

  81. Umesh Kumar Avatar

    Umesh Kumar

    March 4, 2014

    Thanks for the Plugin suggestion, I couldn’t make relay setup working being in hurry but the Plugin WP Mail SMTP works great for me.

    1. Rahul Bansal Avatar

      Rahul Bansal

      March 7, 2014

      Where did you get stuck? WP Mail SMTP plugin might slow down few WordPress feature as SMTP connections are generally blocking in nature.

      Using relay host is useful as postfix uses mail queue.

  82. daniel_mullins Avatar

    daniel_mullins

    March 10, 2014

    This is a great tutorial! Followed step by step and was able to get it working. Had some issue with sendmail already running on port 25, but I removed it and rebooted and now it works like a champ!

  83. Jorge Saldivar Avatar

    Jorge Saldivar

    March 10, 2014

    After several trials getting this error message “SASL authentication failed; server smtp.gmail.com” I could finally manage by unlocking the captcha visiting this page https://www.google.com/accounts/DisplayUnlockCaptcha

    1. Rahul Bansal Avatar

      Rahul Bansal

      March 14, 2014

      Yep. Already covered it here: https://rtcamp.com/tutorials/linux/ubuntu-postfix-gmail-smtp/#comment-52591

      I will add this to main article so it can be easily found.

  84. Christopher S Wells Avatar

    Christopher S Wells

    March 13, 2014

    Every time i boot my server, I get that test mail… x2 and every now and again while its up… how to fix. thanks

    1. Rahul Bansal Avatar

      Rahul Bansal

      March 14, 2014

      This is not related to this article. This article doesn’t have test mail sending on boot.

      Anyway, check crontab. It looks like cronjob.

  85. john Avatar

    john

    March 16, 2014

    hi. really nice tutorial. i got it working simply by following this tutorial.
    when i send emails, the recipient sees root (as name, the email address appears correctly).
    it appears as root is there a way to change the root to another name.
    when i send from my thunderbird using this email address it appears the name i have setup.

    1. Rahul Bansal Avatar

      Rahul Bansal

      March 19, 2014

      Can you verify if sent mails are appearing in Gmail’s “Sent” folder/label?

      1. john Avatar

        john

        March 20, 2014

        yes, the messages appear in sent folder of gmail

        1. Rahul Bansal Avatar

          Rahul Bansal

          March 22, 2014

          I think next thing to do is specify FROM: header while sending mail. Not sure if it will work.

  86. pergaet Avatar

    pergaet

    March 16, 2014

    I get the following log message from gmail: “….The IP you’re using to send mail is not authorized to 550-5.7.1 send email directly to our servers. Please use the SMTP relay at your 550-5.7.1 service provider instead…. ”
    Could you suggest a workaround?

    1. Rahul Bansal Avatar

      Rahul Bansal

      March 19, 2014

      Looks like your mails are not sent via Gmail SMTP. Verify it first.

  87. Orlando Combita Avatar

    Orlando Combita

    March 22, 2014

    Nice and Clear! Thanks a lot Rahul!. I’m on my way to develop a testing server for a php app! Your artice was very helpful

    1. Rahul Bansal Avatar

      Rahul Bansal

      March 22, 2014

      Glad to know that. 🙂

  88. Tom Avatar

    Tom

    March 22, 2014

    Clear and working!
    thanks a lot!

  89. Sohail Avatar

    Sohail

    March 24, 2014

    Thanks @Rahul,
    I have one issue though, if you could help.

    I have installed it as you explained it here step by step for my WordPress site. I use Contact Form7 plugin for creating my forms. So I am able to send emails, but the Sender address in all those emails is what I have entered in sasl_passwd file. And it ignores the Sendaddress in the ContactFrom7 plugin. Is there a solution for this ?

    1. Rahul Bansal Avatar

      Rahul Bansal

      March 24, 2014

      You can login to Gmail, add add other email addresses to your account. See: https://support.google.com/mail/answer/22370?hl=en

      It might work!

  90. That Jack Elliott Avatar

    That Jack Elliott

    March 25, 2014

    Rahul: It didn’t work perfectly initially. But commenter’s followup questions echoed my issues. The machine said “bind 0.0.0.0 port 25: Address already in use. ” You suggested that this might be due to “some other mail program is already present in your system.” I did “apt-get –purge remive sendmail” to get rid of my best guess, but apparently sendmail it had its claws sunk deep into the OS: I continued to get errors when I did your example test.

    But one reboot and Hey Presto! it sends mail!

    Many thanks, Rahul! It works good. Thank you for writing up this very handy how-to.

    One wonders how you figured it out?

Features

Useful Links

Product

Other Products

Subscribe for curated product updates, tips, and announcements.

"*" indicates required fields

Phone

This field is for validation purposes and should be left unchanged.

Email*

SIGN ME UP

Δ


© rtCamp, since 2009. All rights reserved.

Powered by