Configure Postfix to sent emails using MailGun
First install requirements
1 |
apt-get update && apt-get install postfix libsasl2-modules -y |
Run
1 2 3 |
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
1 |
vi /etc/postfix/main.cf |
Add
1 2 3 4 5 |
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
1 |
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
1 |
postmap /etc/postfix/sasl_passwd |
Restart postfix
1 |
service postfix restart |
You can test email with
1 |
echo "test" | mail -s "test" admin@serverok.in |