Sending e-mails from web app

I decided that part of the results created by the project will be provided to users by email. I have my site run by cherrypy (Python 3) on Ubuntu 16.04 (I used until recently 14.04 and everything worked on both systems) located at DigitalOcean.

What I wanted was to send emails from specific email address (using my domain name), ensure that emails won’t end up in the spam folder and redirect all emails send to any email address on my domain to specific email.

Easiest solution was postfix.

First attempt resulted in successful email sending, however, directly to spam folder. To solve this issue, there are some online free software to check what is wrong with the emails sent. Just to name some:

https://www.mail-tester.com/

http://isnotspam.com/

Actually,  I liked the latter better. First has restrictions about number of free usages per day and despite of not so user-friendly interface it was easier for me to draw some conclusions from the latter. Most important was:

  1. HELO greeting
  2. SPF
  3. DKIM

HELO was easiest as it is set in postfix configuration.

SPF need to be changed on the site of DNS (for me it was on DigitalOcean site).

For DKIM I used opendkim (and other perl libraries needed for opendkim proper functioning).

And that did the trick, I can send emails and receive emails as well.

Inside the app (cherrypy) I use smtplib for sending emails and email.mime for formatting emails and attachments (there are some differences in mime use between Python2 and Python3).

And it’s up and running :).

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s