[SalesForce] SingleEmailMessage Bounce Message Not Recieved

When using singleEmailMessage I would expect to get a failure or bounce notification if the email cannot be delivered. The code below sends successfully to a valid email address but does not fail or generate a bounce message report when an invalid email address is used. Anyone know why I am not getting a bounce email notification? Or how I could get this notification. Thank You!!


Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

mail.setToAddresses(new String[]{'bpirihINVALID@mydomain.com'} );
mail.setHtmlBody('testhtml');
mail.setPlainTextBody('test plain text');
mail.setSubject('Test Failure');
mail.setBccSender(false);
mail.setUseSignature(false);

mail.setSaveAsActivity(false);

list emailList = new list();
emailList.add(mail);


Messaging.SingleEmailMessage mail1 = new Messaging.SingleEmailMessage();

mail1.setToAddresses(new String[]{'bpirih@mydomain.com'} );
mail1.setHtmlBody('testhtml');
mail1.setPlainTextBody('test plain text');
mail1.setSubject('Test Successful');
mail1.setBccSender(false);
mail1.setUseSignature(false);

mail1.setSaveAsActivity(false);

emailList.add(mail1);



list results = Messaging.sendEmail( emailList, false);

            for( Messaging.SendEmailResult currentResult : results ) 
            {
                system.debug(currentResult.isSuccess());

                if ( !currentResult.isSuccess() )
                {
                    Messaging.SendEmailError[] errors = currentResult.getErrors();

                    if( null != errors ) 
                    {
                        for( Messaging.SendEmailError currentError : errors ) 
                        {
                            system.debug('currentError: ' + currentError);
                            system.debug(currentError.getStatusCode() + ' ' + currentError.getMessage());
                        }
                    }
                }
            }
 

Best Answer

From salesforce support

"SendEmail "success" indicates that the salesforce.com MTA tentatively accepted the email. It is actually placed into a mail queue for later delivery (only after the current transaction completes). This is necessary because salesforce.com does not send the email until after the transaction completes. Any uncaught exception will cancel the email from being sent, as if it hadn't happened. There's no programmatic access to email logs; the "Request Email Log" actually queries the MTA's logs for emails sent from the organization. This data isn't specifically stored "in salesforce.com" proper, and thus, there's no access to the information directly."

Related Topic