3

I have a quick question about accessing a MySQL database via Postfix and adding a custom header to an email based on the result. So we have setup an Ubuntu server with Postfix which is using a MySQL DB for virtual addresses, now my question is this: Is it possible to lookup an address in the virtual addresses table and if it matches the search criteria, add a custom Header to the email? We would also need this to happen when the email arrives in case there are any forwarders attached to the email account.

I have found resources on how to add custom headers via Postfix: http://saaboke.com/?p=22, but I do not know how to incorporate that with MySQL. Any suggestions would be greatly appreciated.

Thanks for your time.

thiesdiggity
  • 437
  • 1
  • 9
  • 22
  • Please add more information. Do you want the header to be a result of a virtual address lookup? Or want to do a mysql query based on the recipient and then add the result to the header? – mailq Aug 18 '11 at 18:52
  • Hey mailq, sorry I want to add Header information based on the recipient. So if the receipents record is found in the MySQL query (with specific search criteria) result it will add custom headers to the email. If a record is not found then it won't add anything. – thiesdiggity Aug 18 '11 at 19:36

1 Answers1

5

That's an easy one. You need something to add to the

 smtp_recipient_restrictions = (...), check_recipient_access mysql:/etc/postfix/header_based_on_recipient.mysql, (...), permit

The /etc/postfix/header_based_on_recipient.mysql must contain everything needed to query mysql as described here. I can't give you a template as it depends on what you are trying to query.

The result of the query must be blank to add no header. Or the result of the query must be

PREPEND X-fancy-new-header: Found you in the database

If you need more than one header, then this is not applicable. In this case you should consider using the MILTER interface with a self-made milter. Doing such extended stuff is not the job of Postfix and is delegated to external programs as Postfix is a mailer and not a message rewriter.

I'm sorry - as a Postfix lover - to recommend Exim for extended message manipulation as such things are built-in to Exim.

mailq
  • 17,023
  • 2
  • 37
  • 69
  • Hey mailq, thanks for the answer! Unfortnately I'm required to add a couple custom headers to the email. I will look into creating a milter. – thiesdiggity Aug 19 '11 at 16:07