Tag: postfix mailgun

  • Configure Postfix to sent emails using MailGun

    First install requirements

    apt-get update && apt-get install postfix libsasl2-modules -y
    

    Run

    sed -i "s/default_transport = error/# default_transport = error/g" /etc/postfix/main.cf
    sed -i "s/relay_transport = error/# relay_transport = error/g" /etc/postfix/main.cf
    sed -i "s/relayhost =/# relayhost =/g" /etc/postfix/main.cf
    

    Edit /etc/postfix/main.cf

    vi /etc/postfix/main.cf
    

    Add

    relayhost = [smtp.mailgun.org]:2525
    smtp_tls_security_level = encrypt
    smtp_sasl_auth_enable = yes
    smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
    smtp_sasl_security_options = noanonymous
    

    Create file /etc/postfix/sasl_passwd

    echo "[smtp.mailgun.org]:2525 SMTP_LOGIN:SMTP_PASSWORD" > /etc/postfix/sasl_passwd
    

    Replace SMTP_LOGIN and SMTP_PASSWORD with your user and password you get from mailgun.

    Run

    postmap /etc/postfix/sasl_passwd
    

    Restart postfix

    service postfix restart
    

    You can test email with

    echo "test" | mail -s "test" [email protected]