Question

I have a web app. Lets assume it's domain is example.com. So, I need to make this thing. Anyone can send email to any email address in my domain. For instance, to 123@example.com, or to abc321@examle.com. And I need to get this message, detect address ('123', 'abc321',...) and add this message to a database, or call a special python script to parse message. So, finally, I need to store in database: to-address, subject, message body, from address.

I'll appreciate any help. I don't know from where to start.

Was it helpful?

Solution

Most good email servers will have this feature. It's called a catch-all account, where all email sent to *@domain.com will get dumped if it didn't match a user account somewhere. In your case, setup a single user account, and set it as the catch all.

In the email headers, it will show you who the original message was sent to, irreguardless of who that message was redirected to within your mail server.

If you're interested in losing some sleep, some hair and some sanity, you can go ahead and build your own mail server quite quickly using the awesome qmailrocks tutorial guides. Just pick your platform on the right and away you go. Here's how you can setup a catchall, though better guides exist if you google for it. You could easily run this server anywhere, including a free tier AWS EC2 instance (if you haven't already used up your initial quota).

If you don't want to actually setup and host your own email account, you can pay someone like Google $5USD/month to use their Google Apps for Business (which I do also). They allow a catch-all account to be setup there. The major benefit here is google's amazing gmail spam filtering and vast infrastructure basically means you'll never lose a message.

Last step is to write a python script which logs into this mail server as the catch-all user, and processes messages. There's plenty of tutorials out there which show you how to connect from Python to an IMAP email server, so i'm not going to detail that here.

Have fun and don't be too amazed at the amount of spam you're parsing through.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top