+ Start a Discussion
PatlatusPatlatus 

Monitoring delivering of emails sent by salesforce by source code

Hello.

I have following questions.

Assuming I have following code

public class MessageMaker {
	public static void helloMessage() {
		System.debug( 'Entry point' );
        
        Case c = new Case();
        insert c;
        
        EmailMessage e = new EmailMessage();
        System.debug( 'EmailMessage created' );
        e.parentid = c.id;
        // Set to draft status.
        // This status is required 
        // for sendEmailMessage().
        e.Status = '5'; 
        e.TextBody = 
          'Sample email message.';
        e.Subject = 'Apex sample';
        e.ToAddress = 'my@mail.com';
        insert e;
        
        List<Messaging.SendEmailResult> 
          results = 
          Messaging.sendEmailMessage(new ID[] 
            { e.id });
        System.debug(results.size());
        System.debug(results[0].success);       
        System.debug(results[0].getErrors().size());
        System.assertEquals(1, results.size());
        System.assertEquals(true, results[0].success);

	}
}

1. First question.

 I want to find out using apex code if the message was really delivered.

 

Here documentation says

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_sendemail_emailresult.htm

Even if success = true, it does not mean the intended recipients received the email, as it could have bounced or been blocked by a spam blocker. Also, even if the email is successfully accepted for delivery by the message transfer agent, there can still be errors in the error array related to individual addresses within the email.

 

 So I have been trying to send email by apex code and look for results[0].success.

It seems it says like it is described in documentation, so success is true even though email address was incorrect.

 

Also I have tried to check this manually through email logs 

http://eu2.salesforce.com/help/doc/en/email_logs.htm

 

And I have found following row in resulting log regarding my email sent to incorrect address

 

9/2/2013 9:36 66/FC-09306-20B54225 T julfy@i.ia julfy=i.ua__0-6uvic1ltvun1nf@95mngihd2hpe0w.b-ysubea0.bl.bnc.salesforce.com   1434 005b0000000J7bm <_0vTJ000000000000000000000000000000000000000000000MSHRSY00W1-CKg3DShWC5xu24ccHFA@sfdc.net> 1 311.627583       421 4.4.0 [internal] no MXs for this domain could be reached at this time

 

But I don't know how to access this information by apex code. Any thoughts?

 

2. Second question.

If message was delivered and recipient forwarded it, is any possibility to monitor that using apex code?

Anybody?

cplusplus_pleasecplusplus_please
I'm sorry but aside from downloading the email log each day, extract, and read the code through a program, I don't think there is another way.



=============================
Developer for www.voicent.com
Voicent provides CRM, auto dialer, predictive dialer, reminder, and call center solution that is suitable for anyone in any level
Voicent strives to meet customer demands to integrate Voicent software with CRM of their choice.