From Notes Wiki
Jump to: navigation, search
Home > CentOS > CentOS 8.x > Email servers > postfix > Send email through relay or smarthost with smtp authentication

CentOS 8.x postfix send email through relay or smarthost with smtp authentication

To send email through relay with smtp authentication use:

  1. yum -y install cyrus-sasl cyrus-sasl-plain cyrus-sasl-lib postfix mailx
  2. Note that without cyrus-sasl and related packages error no worthy mechanisms found would be received while authenticating to relay server via postfix. Refer
  3. Set at least following in /etc/postfix/ for mail system to work properly:
    inet_interfaces = all
    inet_protocols = ipv4
  4. edit /etc/postfix/sasl_passwd and put something like
    <smtp-server>:<port-number> <username-or-email-address>:<password>
    For example in case of gmail use: <gmail-email-address>:<gmail-password>
  5. Create hash postmap of sasl_password using:
    cd /etc/postfix
    chmod 600 sasl_passwd
    postmap hash:/etc/postfix/sasl_passwd
  6. edit /etc/postfix/ and after relayhost comment lines insert
    smtp_sasl_auth_enable = yes
    smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
    smtp_sasl_security_options =
    smtp_tls_security_level = may
    relayhost = <relay-server>:<relay-port>
    Often relay port will be submission port (587) and not smtp port (25). Example
  7. Start and enable postfix:
    systemctl start postfix
    systemctl enable postfix
  8. echo "Test email using postfix" | mail -s "Relay test with smtp authentication"
  9. Look for successful email being sent or errors logs using:
    tail -50 /var/log/maillog
    Also consider looking at destinatino email server /var/log/maillog if you have access to it for more information

To troubleshoot look at /var/log/maillog. In log lines look at value of ctladdr such as 'ctladdr=saurabh (501/501)'. Then look at /var/mail/saurabh or login as user saurabh and use 'mail' command to see error message sent by relay server.

Sending emails using Gmail SMTP server as relay

Note that Gmail requires enabling less secure apps for this to work. Also note that Gmail is likely to stop support for less secure apps very soon (See ). Most of emails sent via gmail using this technique neither seem to get delivered neither bounce back!!!. Ideally use your own SMTP server instead of relying on gmail for sending emails.

  1. Configure gmail to use less secure apps using:
    1. Login into Gmail account and go to Settings -> Accounts -> Google Account Settings
    2. In "Google Account Settings" go to Sign-in and Security.
    3. In Sign-in and security change "Allow less secure apps:" to ON
  2. Logging into above configured "Less secure Gmail" account via browser also helps for troubleshooting in case emails fail to deliver

There is older article on this at Sending email via Gmail relay through postfix

Home > CentOS > CentOS 8.x > Email servers > postfix > Send email through relay or smarthost with smtp authentication