Search This Blog

Configure postfix to send emails via smtp.gmail.com

  1. Install postfix:
    apt-get install postfix libsasl2-2 ca-certificates libsasl2-modules
    
    • SMTP relay host: smtp.gmail.com:587
  2. Configure postfix by editing /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
    
  3. Create /etc/postfix/sasl_passwd file, which contains the gmail user name and password in the following format:
    smtp.gmail.com:587    username@gmail.com:password
    
  4. Generate /etc/postfix/sasl_passwd.db file using postmap:
    sudo postmap /etc/postfix/sasl_passwd
    
  5. Secure the files by setting file permissions:
    sudo chmod 400 /etc/postfix/sasl_passwd*
    
  6. Set up CA certificate for postfix:
    cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | sudo tee -a /etc/postfix/cacert.pem
    
  7. Reload postfix:
    /etc/init.d/postfix reload
    



Note:

  • The commands above tested on Ubuntu Linux 11.10
  • To send a test email from command line:
    echo "this is a test mail." | mail -s "test" youremail@yourdomain.org
    
  • if mail is not installed, try
    sudo apt-get install mailutils
    



No comments:

Post a Comment