You need to sign in to do that
Don't have an account?
Error attempting to send email to invalid email address -- not being caught by try/catch
I have the following code: (Note, it is part of a future-call method)
... String EmailFailure = null; try { Messaging.SendEmailResult[] mailResult = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); if ( !mailResult[0].isSuccess() ) { EmailFailure = 'Email Failed: ' + mailResult[0].getErrors()[0].getMessage(); } } catch(DmlException dmlEx) { EmailFailure = 'Email Failed: ' + dmlEx; } if ( EmailFailure != null ) { ...
It is failing with the following error whenever an attempt is made to send to a contact with an invalid (bounced) email address.
Failed to invoke future method 'public static void SendSurvey(String, Id, Id, Id, Id, Id, String, String)' on class 'Survey_Controller' for job id '70730000003xhE1' caused by: System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_EMAIL_ADDRESS, email address has bounced for id : 0033000000VqJyN: []
How can I capture the error gracefully instead of getting this error message? I thought if I wrapped it with try/catch it would work.
Thanks,
Paul
Paul,
Can you try to catch the EMail exception:
Exception types and methods can be found at
http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_classes_exception_methods.htm?SearchType=Stem.
Hope this helps.
Jay
All Answers
Paul,
Can you try to catch the EMail exception:
Exception types and methods can be found at
http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_classes_exception_methods.htm?SearchType=Stem.
Hope this helps.
Jay
I had been using an "example" of exception catching, and it had been working for me in test methods (for catching DML errors). I hadn't even realized that error catching was specific to the exception type being thrown. Thanks for this reply, I was able to fix my code to appropriately catch the invalid-email errors now.
Thanks!
Paul
Hi.
I tried your method not working.
List<Messaging.SendEmailResult> results = new List<Messaging.SendEmailResult>{};
try{
results = Messaging.sendEmail(allMails);
}catch(EmailException emlEx) {
msg = String.valueof('msg:' + emlEx);
System.debug(msg);
}
I sending a bunch of mails,so is there any time delay from email server which responses to SFDC server.
cheers
suresh
There should be no time delay in sending.
What is the error that you are receiving? You should try an catch all of the different exceptions. Can you add a catch for the DML exception?
From your code snip, I cannot really tell what is happening (what is allMails). What happens if you use the sample code above?
Thanks
Jay