How do I get started processing email related to website activity?

I am writing a web application that requires user interaction via email. I'm curious if there is a best practice or recommended source for learning about processing email. I am writing my application in Python, but I'm not sure what mail server to use or how to format the message or subject line to account for automated processing. I'm also looking for guidance on processing bouncebacks.

Asked by: Fiona643 | Posted: 28-01-2022

Answer 1

There are some pretty serious concerns here for how to send email automatically, and here are a few:

Use an email library. Python includes one called 'email'. This is your friend, it will stop you from doing anything tragically wrong. Read an example from the Python Manual.

Some points that will stop you from getting blocked by spam filters:

Always send from a valid email address. You must be able to send email to this address and have it received (it can go into /dev/null after it's received, but it must be possible to /deliver/ there). This will stop spam filters that do Sender Address Verification from blocking your mail.

The email address you send from on the server.sendmail(fromaddr, [toaddr]) line will be where bounces go. The From: line in the email is a totally different address, and that's where mail will go when the user hits 'Reply:'. Use this to your advantage, bounces can go to one place, while reply goes to another.

Send email to a local mail server, I recommend postfix. This local server will receive your mail and be responsible for sending it to your upstream server. Once it has been delivered to the local server, treat it as 'sent' from a programmatic point of view.

If you have a site that is on a static ip in a datacenter of good reputation, don't be afraid to simply relay the mail directly to the internet. If you're in a datacenter full of script kiddies and spammers, you will need to relay this mail via a public MTA of good reputation, hopefully you will be able to work this out without a hassle.

Don't send an email in only HTML. Always send it in Plain and HTML, or just Plain. Be nice, I use a text only email client, and you don't want to annoy me.

Verify that you're not running SPF on your email domain, or get it configured to allow your server to send the mail. Do this by doing a TXT lookup on your domain.

$ dig txt
;; ANSWER SECTION:     300 IN  TXT "v=spf1 ~all"

As you can see from that result, there's an SPF record there. If you don't have SPF, there won't be a TXT record. Read more about SPF on wikipedia.

Hope that helps.

Answered by: Dexter581 | Posted: 01-03-2022

Answer 2

Some general information with regards to automated mail processing...

First, the mail server "brand" itself isn't that important for broadcasting or receiving emails. All of them support the standard smtp / pop3 communications protocol. Most even have IMAP support and have some level of spam filtering. That said, try to use a current generation email server.

Second, be aware that in an effort to reduce spam a lot of the receiving mail servers out there will simply throw a message away instead of responding back that a mail account doesn't exist. Which means you may not receive those.

Bear in mind that getting past spam filters is an art. A number of isp's watch for duplicate messages, messages that look like spam based on keywords or other content, etc. This is sometimes independent of the quantity of messages sent; I've seen messages with as few as 50 copies get blocked by AOL even though they were legitimate emails. So, testing is your friend and look into this article on wikipedia on anti-spam techniques. Then make sure your not doing that crap.


As far as processing the messages, just remember it's a queued system. Connect to the server via POP3 to retrieve messages, open it, do some action, delete the message or archive it, and move on.

With regards to bouncebacks, let the mail server do most of the work. You should be able to configure it to notify a certain email account on the server in the event that it is unable to deliver a message. You can check that account periodically and process the Non Delivery Reports as necessary.

Answered by: Alberta439 | Posted: 01-03-2022

Similar questions

Showing processing message in Python

I want to show the processing information or log in the original page when the submitted request is being served until it completes the execution. I thought it would be meaningful to the user to know what is happening behind the request. I don't find a clue to do so though, can you guys help me out as how people are doing like this one below one - for your reference

Parallel processing from a command queue on Linux (bash, python, ruby... whatever)

I have a list/queue of 200 commands that I need to run in a shell on a Linux server. I only want to have a maximum of 10 processes running (from the queue) at once. Some processes will take a few seconds to complete, other processes will take much longer. When a process finishes I want the next command to be "popped" from the queue and executed. Does anyone have code to solve this problem?

python - Processing XML into MySQL in good form

I need to process XML documents of varying formats into records in a MySQL database on a daily basis. The data I need from each XML document is interspersed with a good deal of data I don't need, and each document's node names are different. For example: source #1: <object id="1"> <title>URL 1</title> <url></url> <frequency interval="6...

Further Processing of Output of Undefined Methods (Python)

How do I write a Python class that handles calls on undefined methods by first, getting the output of a function of the same name from a given module, and then, doing something further with that output? For example, given add(x, y), doublerInstance.add(1, 1) should return 4. I know _ _ getattr _ _() intercepts calls on undefined methods, and getattr() can retrieve a function object. But I don't know how ge...

Looking for the "Hello World" of ctypes unicode processing (including both Python and C code)

Can someone show me a really simple Python ctypes example involving Unicode strings including the C code? Say, a way to take a Python Unicode string and pass it to a C function which catenates it with itself and returns that to Python, which prints it.

python - Django payment processing

Closed. This question does not meet Stack Overflow guid...

pygame - Emulate processing with python?

I'm looking for a basic programmatic animation framework similar to processing except in python. That is, something that allows pixel manipulation, has basic drawing/color primitives, and is geared towards animation. Is pygame pretty much the best bet or are there other options?

python - How can I parse marked up text for further processing?

See updated input and output data at Edit-1. What I am trying to accomplish is turning + 1 + 1.1 + 1.1.1 - - + 1.2 - 1.2.1 - 1.2.2 - 1.3 + 2 - 3 into a python data structure such as [{'1': [{'1.1': {'1.1.1': ['', '']}, '1.2': ['1.2.1', '1.2.2']}, '1.3'], '2': {}}, ['3',]] I've looked at many differ...

Python: Multicore processing?

I've been reading about Python's multiprocessing module. I still don't think I have a very good understanding of what it can do. Let's say I have a quadcore processor and I have a list with 1,000,000 integers and I want the sum of all the integers. I could simply do: list_sum = sum(my_list) But thi...

Most used Python module for video processing?

Closed. This question needs to be more focused. It ...

Still can't find your answer? Check out these communities...

PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python