0

I have Magento using Sendmail and Wordpress using PHPmailer to send webapp-generated mail. Occasionally, someone will enter their email address incorrectly and the mail (let's say, a purchase receipt) will bounce back to the return-path specified by the script.

I dont want to set the return path for each vhost, especially because it is not easily done. Ideally, WP would use the address of the blog admin and Magento would use one of the numerous email fields specified, but they default to using username@machinename (in my case, username is the system user and machinename is a FQDN, but it is not the same as the actual vhost FQDN). The result is that bounced mail returns to the server and, since the server is used only for outbound SMTP, the messages sit there, undelivered and worse, unread.

I'm Postfix 2.6.6 on CentOS 6.3, is it possible to globally force a specific returnpath for all messages sent via PHP on the server?

Gaia
  • 1,855
  • 5
  • 34
  • 60
  • If I could create an alias in postfix like *@machinename (redirecting to bouncedmail@mydomain.com) my problem would be solved. I know I can create one alias for each vhost, but there has got to be a more elegant solution than this, even if the solution involves the webserver processing bounced mail, as opposed to having the return-path make it go to bouncedmail@mydomain.com directly (the most desirable solution, as stated above). – Gaia Oct 27 '12 at 15:56
  • Obviously setting `Sender` is not what you want, and PHP mailer defaulting to `From` for the return path is not what you want either (these were mentioned in the linked questions), but can you clarify why? – chutz Oct 27 '12 at 23:56
  • You should really consider changing the `From` address in your application. There are spam filters out there that reject mails coming from non-existent mail addresses. – chutz Oct 28 '12 at 03:31
  • I'm sorry, the from is fine. the returnpath needs adjustment! – Gaia Oct 28 '12 at 11:16
  • sorry, `from` is fine. `returnpath` is systemusername@machinename.com while it should be desirablemailbox@desirabledomain.com – Gaia Oct 28 '12 at 12:50
  • forgot to mention you on the last comment, @chutz! – Gaia Oct 28 '12 at 19:52

2 Answers2

0

It sounds like all you need to do is set the Sender property for your phpmailer. The description in the official documentation says that $Sender is a public property, with no default, and it...

Sets the Sender email (Return-Path) of the message. If not empty, will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.

Something like this?

$phpmailer->Sender = "desirablemailbox@desirabledomain.com";

Alternatively, if you want a generic return-path for all your scripts you can either modify the phpmailer class itself and set the default Sender to not be blank, or make yourself a wrapper class that sets it to that value.

Setting a global value for PHP is not doable, because there is nothing to stop you from opening a socket to a remote SMTP server and sending the email directly. And there is nothing stopping you from connecting to localhost:25 and sending a mail with a different Return-Path from the one you are trying to use. Or invoking the sendmail binary directly. There are many ways of sending email (phpmailer is just one of them) and a global setting is just not feasible. The best you can do is make sure that you configure properly the one way you are using.

chutz
  • 7,888
  • 1
  • 29
  • 59
  • as mentioned, I am not looking to set the `Sender` property for each one of the PHPmailer scripts in the server, nor that takes care of the webapps that use something other than PHPmailer. – Gaia Oct 28 '12 at 17:15
0

Solution found! With help from the answers by @Dom & @Oguz in this question, I created entries in sender_canonical_maps.

The name part of the map is each username (which corresponds to the user@ part in the undesirable user@machinename previous setting, since postfix does not use sender canonical maps by default) and the maps to part is an email address like bounces-userA@mymaindomain.com, bounces-userB@mymaindomain.com, bounces-userC@mymaindomain.com, etc

It is important that the address bounces-user@ does NOT exist as a mailbox in the destination domain. IF the address exists, some mail service providers (such as google apps) will classify the email as spam because it KNOWS you didnt send the email (remember the email was generated by a webapp on some server), calling it a fake bounce, a technique used by spammers. Therefore, you need to either have catchall turned on for the mail service tending to mymaindomain.com OR you need to create aliases for bounces-userA@mymaindomain.com, bounces-userB@mymaindomain.com, bounces-userC@mymaindomain.com, etc

Note that I didnt I create a different mapping for each one of the domains like bounces@domainA.com, bounces@domainB.com, bounces@domainC.com. You can only do this if you know that bounces@ does NOT exist on each one of the domains AND they have catchall OR an alias for bounces@ created. Doing that for each one of the domains is too much work, so the next step was to create a rule (or a filter, in google maps parlance) in @mymaindomain.com to redirect each bounce notification message to an appropriate, human receiver on domainA, domainB, domainC and so forth.

This is the best solution I could come up with. If you have hundreds of domains this could become hard to manage, but it is ok in my case.

I hope this helps

Gaia
  • 1,855
  • 5
  • 34
  • 60
  • I know that `empty_address_recipient` doesnt do it. I wonder if there was an easier way to solve this problem via setting `myorigin`, `mydomainname `OR `myhostname`. – Gaia Oct 29 '12 at 01:31