Question

I need to be able to display ads on email forwarded through a server (preferably postfix) based on the demographic information of the recipient. Basically a message will arrive for someuser@fakedomain.com and be forwarded to realuser@theirdomain.com with a small advertisement at the bottom.

I would like to use postfix because it appears to be able to use mysql data for various tasks, which would be beneficial so that the system could be controlled by a web app that feeds the database.

I'd prefer to use OpenX for the ad server due to targetting channels (used to select ads based on demographic information), the ability to do text ads as well as email zones, and the ability to run it locally. Other ad servers that are better suited to this problem are acceptable, of course.

The core of the problem, as I see it, is being able to write something at the bottom of any given email message. Of course html messages make this even trickier, but I'd settle for having a solution that works for plain text and work up from there.

Commercial software is an option as well, but a few days of intermittent searching hasn't turned anything up.

Was it helpful?

Solution

Simply writing something to the bottom of the email message will fail miserably in a LOT of cases, particularly with HTML email encapsulated in a MIME multipart message (or anything else in a MIME multipart message) because anything after the last MIME section marker is explicitly supposed to be ignored by any MIME parser. If you want your app to work it needs to

  • determine if the target message is a MIME message other than TEXT/PLAIN
    • If it is not, append your text only ad at the end and you're done
  • if it is, determine if its multipart
    • if not, then you need to determine the content type of the whole message
      • If the content type is HTML then you can attempt to insert your ad HTML somewhere appropriate. This will be very hit or miss since you have no idea what the HTML layout will be like.
      • if the content type is anything OTHER than HTML (or maybe RTF), you're best off not touching the message.
  • If the message is multipart, determine the subtype
    • if its 'mixed', then you need to determine which part if any is the primary readable content, and then modify that portion as if it were the whole message based on the above rules
    • If its 'alternative' then you need to find ALL the readable portions and modify each of them in turn according to the above rules

Finally, and most importantly

  • Be prepared for the massive ill will you will receive from everyone who gets mail routed through your server.

OTHER TIPS

Let me see... People sign up for your service, which I assume is free. They provide you their real email address and in return you provide them a different email address which they can use to e.g. subscribe to mailinglists and for other services. And maybe some spamfilter functionality? That sounds like a legit service to me, especially if you only provide the ads to the person who subscribed. I do wonder if you'd get many subscriptions, though, since many people can just as easy use a Google, Yahoo or Hotmail account for these purposes. So, what is the added value those subscribers will get?

Anyway, you would need to modify existing emails, which is a bit complex when they are HTML mails or if they're digitally signed. (Especially in the latter case, you would actually block the recipient from receiving those emails, since their email system would detect that the email has been tampered with. You might also be at risk of possible legal problems, although I don't think there's anything illegal as long as the recipient agrees with the terms of your service.

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