views:

178

answers:

1

Hi,

I'm trying to handle bounced message and send to a responsible System Administrator.

I use CakePHP Email Component to send the message. On server side, I use postfix to transport the message.

function sendAsEmail($data) {
  $Email->sendAs = 'html';
  $Email->from = $user['Sender']['username'] . '@example.com';
  $Email->return = Configure::read('App.systemAdminEmail');
  $Email->bcc = array($data['Message']['recipient_text']);
  $content = 'Some content';
  $Email->send($content);
}

As you can see above, I set the $Email->return to sysadmin's email which it will send all the bounced message.

On postfix configuration, I tried creating a bounce.cf template and set bounce_template_file. http://www.howtoforge.com/configure-custom-postfix-bounce-messages

How do I get the bounced message and send it to System Administrator?

A: 

I think what you'll need to do is to use an SMTP (or I suppose POP3) connector for PHP. Then you'll basically have to create your own PHP email client that will login to the server, ask for the messages that have been bounced, and parse them appropriately.

I would think there would be a CakePHP component for this, but I can't find one.

I would recommend that you use an Envelope Header in your email. Otherwise you'll be stuck trying to parse the recipient server bounce, and those are very very inconsistent. If you use the VERP (variable envelope return protocol?) header, you can encode a unique hash into the email address which should be really easy to parse out in your PHPEmailClient.

More info on VERP: http://en.wikipedia.org/wiki/Variable_envelope_return_path

Cake-specific VERP stuff: http://www.mainelydesign.com/blog/view/setting-envelope-from-header-cakephp-email-component

I also highly recommend that you look into using SwiftMailer. It has a lot of plugins; you might find a base PHP SMTP client that you can easily modify to do what you need. http://swiftmailer.org/

Travis Leleu