You need to sign in to do that
Don't have an account?
Messaging.sendMail and undeliverable messages
Hello all,
I am having an issue using Messaging.sendMail when the email is sent to an undeliverable email address.
I have the 'ReplyTo' on the email message set to a mailing list, so that if a customer has questions, they can respond to the list of users who can help them. However, when the email address provided for the email message is invalid, an undeliverable message is not delivered to this mailing list. In fact, I can't seem to find where this undeliverable message is being delivered.
As this is a customer facing email, I need to be able to alert my users when it is undeliverable so that they can take appropriate action.
/* public Messaging.SingleEmailMessage buildEmailMessage()
* Description: This method generates the email message which will be sent to the Contact and any CCEmails identified for an instance of this class
*/
public Messaging.SingleEmailMessage buildEmailMessage()
{
// Create a new SingleEmailMessage record
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
// Set the 'Reply To' and 'Sender Display Name' value of the email alias for the mailing list
mail.setReplyTo('mailing-list@my-company.com');
mail.setSenderDisplayName('My Company');
// Fetch the email address for the current user
User currentUser = [Select Id, Email from User where Id = :UserInfo.getUserId() limit 1];
// Set the To and CC addresses for the email
mail.setToAddresses(new String[] {this.contEmail});
if (this.CCEMails != null && this.CCEmails != '')
mail.setCcAddresses(this.CCEmails.split(';'));
// Add the current user's email address to the BCC line
mail.setBccAddresses(new String[] {currentUser.Email});
// Use the currently logged in user's signature
mail.setUseSignature(true);
// Set the subject of the email
mail.setSubject('Email subject line');
// Set the body of the email
mail.setPlainTextBody(buildEmailMessageBody(false));
mail.setHTMLBody(buildEmailMessageBody(true));
// Return the email
return mail;
}
It appears that this issue may have been caused by a mis-configured email address on the user's account. Thanks SanjayS for your assistance in troubleshooting.
Edit: I have confirmed this as the root cause of the issue.
All Answers
The error is returned in the SendEmailResult .Use this object to store the return value and send the email[s] to alert the user
(hope you send it to valid mail id).
Sanjay,
Is that a recent change? The documentation does not indicate this. The documentation I am referencing is found here http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_email_outbound.htm
Specifically, in the 'Messaging' section (emphasis mine),
Unfortunately, my users are reporting that this is not occurring. Do I need to check on my end to see if this is due to spam filters or some other reason?
I've tried modifying my code to check this value. However, when I test it using an invalid email address which should generate an 'Undeliverable' message, the Messaging.SendEmailResult returns a true value when I call its 'isSuccess' method and I get an empty array when I call its 'getErrors' method.
This means I am not getting bounceback emails. We do have 'bounce management' enabled for our organization. Is it possible this is interacting with the outbound email message and preventing the alert from getting to our users?
Check the email confirguration.
https://na15.salesforce.com/help/doc/en/emailadmin_deliverability.htm
It appears that this issue may have been caused by a mis-configured email address on the user's account. Thanks SanjayS for your assistance in troubleshooting.
Edit: I have confirmed this as the root cause of the issue.