MailGun as an SMTP Server for Django Apps
Gmail is a frequently used SMTP host for Django apps. Its free and relatively simple to setup which is ideal for small apps. There are a few significant downfalls. First, its limited to 500 emails a day with no option to upgrade. Second, it limits and even re-writes all outgoing emails to the username of the connector.
For example if you're trying to send an email from firstname.lastname@example.org or email@example.com you're out of luck because all of those emails will actually get sent at firstname.lastname@example.org or whatever email account you have configured. I'm sure this saves millions of people from millions of spam but it adds a bit of annoyance to developer's lives.
The recently launched MailGunoffers a great solution. Its free for up to 200 emails per day and super cheap and dramatically scalable after that. It also works as a drop in replacement for whatever service you were using for your django smtp server. Changing will take you less time than reading this article.
Go to the control panel and click on the YOURHOST.mailgun.org server created for you.
Open the settings.py in your django app and configure your email with the given credentials. It should look something like this.
EMAIL_USE_TLS = True EMAIL_HOST = 'smtp.mailgun.org' EMAIL_HOST_USER = 'postmaster@YOURHOST.mailgun.org' EMAIL_HOST_PASSWORD = 'SOMEPASSWORD' EMAIL_PORT = 587
Test it out!./manage.py shell
from django.core.mail import send_mail send_mail('MailGun works great!', 'It really really does.', 'tester@YOURHOST.com', ['YOUREMAIL@gmail.com'], fail_silently=False)