Configure mailgun on Ubuntu (bsd-mailx / postfix)

1) Install bsd-mailx

aptitude install bsd-mailx

Select Internet Site in the Postfix Configuration screen.

If you missed it or want do reconfigure do:

dpkg-reconfigure postfix

2) Add mailgun configuration

Edit /etc/postfix/main.cf

relayhost = smtp.mailgun.org
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = static:[email protected]:password
smtp_sasl_security_options = noanonymous

3) Restart the postifx service

service postfix restart

Source: https://www.jamroom.net/brian/documentation/guides/1312/set-up-postfix-with-mailgun-for-reliable-e-mail-delivery