Say you have a Django web application that you want to integrate with emails to make it possibile to send data and files to your web application over SMTP.
The good news is that Python has a simple SMTP daemon in the standard library, together with modules to parse emails. Let’s see how to create a simple email gateway on top of these tools.
Using the following Python module you can setup a simple pure Python email server on port 25, parse the incoming emails and make a multipart/form-data POST HTTP request to your web application. You’ll need the awesome Requests library for the HTTP request to work.
In a production environment you can setup supervisor to launch your simple SMTP server. With a simple configuration like this:
Then try to send an email to your server, if the server public IP has been associated to a DNS record yourserver.example.com you can use something like [email protected] as a recipient, and you should see the incoming email in the logs.
Have fun with emails!
You may also like:
A Django custom command to write model fields on an Excel file
Suppose you need to write down your model fields on an Excel file, for example to complement the documentation of your code. Django has built in functions to introspect models and fields of an app, and you can leverage this API to have the information you need. You can use …
How to add a group choice combo box in a Django user profile form
Assume that you have a Django project where each user belongs to just one group, say Registered or Admin, but not both. You want to show a form in your front-end to let Admin users edit the user profiles, where each user profile is made with First name, Last name …
How to migrate your existing Django project to Heroku
Recently I had some fun with Heroku, the well known PaaS provider. I had a small personal Django project I use for invoicing that I ran locally with ./manage.py runserver when needed. That was a perfect candidate for the Heroku free plan because I need to access the app …