Hi
Sugar can only detect an email as bounce if:
- The original email contains a remove me link (the link that contains a tracker identifier)
- The bounced message body also contains the remove me link
The tracker is a unique id that is assigned to any email sent by a sugar campaign and is unique. This way, when one of the targets performs an action (like clicking on the remove me link or clicking on any other tracker link), sugar knows which user performed that action.
When an email bounces back, sugar needs that the bounced back email has the remove me tracker so it can find out which target did not receive the email
What happens is that usually the bounced emails have only the email header and not the body. Therefore, sugar can’t know which target failed to receive the email and just discards that email.
So your bounced email content should look like
================================================== ====
Delivery to the following recipient failed permanently:
ghost@failed_delivery_domain.com
Technical details of permanent failure:
DNS Error: DNS server returned answer with no data
----- Original message -----
Received: by 10.216.163.7 with SMTP id z7mr1538727wek.123.1271414202336;
Fri, 16 Apr 2010 03:36:42 -0700 (PDT)
Return-Path: <no-reply@xxxxx.com>
Received: from xxxxxxxxxx
by xxxx with ESMTPS id xxxx
(version=TLSv1/SSLv3 cipher=RC4-MD5);
Fri, 16 Apr 2010 03:36:39 -0700 (PDT)
Date: Fri, 16 Apr 2010 13:35:00 +0300
Return-Path: no-reply@xxxxx.com
To: Ghost Rider <ghost@failed_delivery_domain.com>
From: no-reply@xxxxxx.com
Reply-to:
Subject: [Test]: Newsletter 05
Message-ID: <9a9d09739ee756170d34160ed043ade3@xxxxxxx.com>
X-Priority: 3
X-Mailer: PHPMailer (phpmailer.codeworxtech.com) [version 2.3]
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="b1_9a9d09739ee756170d34160ed043ade3"
----- End of message -----
================================================== =====================
To solve this, I implemented a solution that writes the sugar tracker directly into the email header. Since headers are usually always available on the body of the bounce message, you just need to search for it.
To implement the work around, follow these steps:
1) edit ..\sugarcrm\modules\EmailMan\EmailMan.php and add the bold line
$mail->ClearAllRecipients();
$mail->ClearReplyTos();
$mail->Sender = $this->mailbox_from_addr;
$mail->From = $this->mailbox_from_addr;
$mail->FromName = $this->current_emailmarketing->from_name;
// I added the following line to get target_tracker_key into the Header of the EMail
$mail->AddCustomHeader("X-SugarCRM-TrackingID:".$this->target_tracker_key)
2) edit ..\sugarcrm\modules\Campaigns\ProcessBouncedEmails .php and change the lines below to the ones shown in bold
//do we have the identifier tag in the email?
$email_description=quoted_printable_decode($email_ description);
$matches=array();
if (preg_match('/index.php\?entryPoint=removeme&identifier=[a-z0-9\-]*/',$email_description,$matches)) {
$identifiers=preg_split('/index.php\?entryPoint=removeme&identifier=/',$matches[0],-1,PREG_SPLIT_NO_EMPTY);
CHANGE TO
//commented this line because the quoted_printable_decode was messing with the remove-me id and bouncing failed because of that
//$email_description=quoted_printable_decode($email_ description);
$matches=array();
if (preg_match('/X-SugarCRM-TrackingID: [a-z0-9\-]*/',$email_description,$matches)) {
$identifiers=preg_split('/X-SugarCRM-TrackingID: /',$matches[0],-1,PREG_SPLIT_NO_EMPTY);
3) additionally, you can enhance the detection of invalid email address by changing the line below to the one shown in bold
//do we have the phrase permanent error in the email body.
if (preg_match('/permanent[ ]*error/',$email_description)) {
CHANGE TO
//do we have the phrase permanent error in the email body.
if (preg_match('/permanent[ ]*error|dns[ ]*error|permanent[ ]*failure/i',$email_description)) {
Your bounced emails should now look like
================================================== ====
Delivery to the following recipient failed permanently:
ghost@failed_delivery_domain.com
Technical details of permanent failure:
DNS Error: DNS server returned answer with no data
----- Original message -----
Received: by 10.216.163.7 with SMTP id z7mr1538727wek.123.1271414202336;
Fri, 16 Apr 2010 03:36:42 -0700 (PDT)
Return-Path: <no-reply@xxxxx.com>
Received: from xxxxxxxxxx
by xxxx with ESMTPS id xxxx
(version=TLSv1/SSLv3 cipher=RC4-MD5);
Fri, 16 Apr 2010 03:36:39 -0700 (PDT)
Date: Fri, 16 Apr 2010 13:35:00 +0300
Return-Path: no-reply@xxxxx.com
To: Ghost Rider <ghost@failed_delivery_domain.com>
From: no-reply@xxxxxx.com
Reply-to:
Subject: [Test]: Newsletter 05
Message-ID: <9a9d09739ee756170d34160ed043ade3@xxxxxxx.com>
X-Priority: 3
X-Mailer: PHPMailer (phpmailer.codeworxtech.com) [version 2.3]
X-SugarCRM-TrackingID: 3b3b0b45-0e20-f230-bc29-4bc83d69d17c
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="b1_9a9d09739ee756170d34160ed043ade3"
----- End of message -----
================================================== =====================
And sugar should detect the bounced emails
This is working perfectly with Sugar 5.5.1. Just remember that it is not upgrade safe and every time there is a new sugar release you will have to perform these code changes.
Cheers
Bookmarks