Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to set up postfix as a relay for Amazon SES. SES will only allow emails to be sent from particular (verified) email addresses. This part works. Now I need to integrate with PHP.

What I need is to support multiple verified email addresses, e.g. site1@example.com, site2@example.com. I need postfix to set the X-Postfix-Sender header to the value of the 'From' header I pass into the mail() call. Unfortunately it sets X-Postfix-Sender: rfc822; ubuntu@ip-10-xx-xx-xx.eu-west-1.compute.internal instead.

I'm sending emails using:

mail('test@example.com', 'PHP test', 'Test message from PHP at ' . $time, "From: site1@example.com");

In the logs I get a refusal from SES: "Diagnostic-Code: smtp; 554 Message rejected: Email address is not verified."

php.ini contains sendmail_path = /usr/sbin/sendmail -t but this doesn't seem to make much difference.

How can I make postfix set the X-Postfix-Sender header to the value of the 'From' header?

========================== ANSWER ==========================

I can do what I want by using the additional_parameters option of PHP's mail() method:

mail('test@example.com', 'PHP test', 'Test message from PHP at ' . $time, '', "-f site1@example.com");

This passes the '-f' flag and a from address to sendmail.

share|improve this question
    
Why not set the X-Postfix-Sender in PHP's mail() function? Using the ini value sendmail_path would also be an option. –  Lukas Mar 12 '13 at 15:40
    
doesn't work. postfix adds it's own anyway that overrides it (appears higher in the message so Amazon read that instead). also sendmail_path won't let me dynamically set the from address. –  Humphrey Tor Mar 12 '13 at 15:42
add comment

1 Answer

You might use the smtp_generic_maps parameter in postfix main configuration file - /etc/postfix/main.cf to rewrite your local domain to a globally valid domain. Check the following links for the details - smtp_generic_maps and how to set it up.

-Add the smtp_generic_maps entry to /etc/postfix/main.cf

  smtp_generic_maps = hash:/etc/postfix/generic

-Create the /etc/postfix/generic file with the following contents

 ubuntu@ip-10-xx-xx-xx.eu-west-1.compute.internal   ubuntu@example.com

Make sure to restart postfix.

share|improve this answer
    
I'm hosting multiple domains, so this may not work since I need the PHP code to determine which 'From' envelope address is set. –  Humphrey Tor Mar 12 '13 at 16:06
    
you can use a unique user in your php code so that postfix will rewrite only that user's domain. –  Daniel t. Mar 12 '13 at 16:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.