salesforce - How to handle error in Messaging.sendEmail()? -


i wrote code send email. works fine goal is:

when sent non-existing email address, want log result 'false' or 'failure' etc (and when email address valid, 'success')

i've tried 2 things code below.

  1. provided non-email string 'foo@!'

  2. provided non-existing email address 'thisdoesnotexistignsdfkjsdf@gmail.com'

result:

execute case 1 caused code go catch block outputting error message on html page expected.

execute case 2 caused code return 'ok sent!'

and after few minutes received email delivery failed.

my guess sendemailresult object's issuccess() not responsible non-existing email address check. cares if email fired???

is there way log if email account not exist can log such occasion in apex code?

try {     messaging.sendemailresult[] resultmail = messaging.sendemail(new             messaging.singleemailmessage[] { mail });      resultmail[0].geterrors();      //display success or error message     if (resultmail[0].issuccess()) {         response = 'ok sent!';     } else {         response = resultmail[0].geterrors().get(0).getmessage();     }      //log     boolean issuccess = resultmail[0].issuccess();     integer out = emaillogger.logemailsent(this, issuccess); } catch (system.emailexception ex) {     system.debug('============== email exception caught!!!=============');     response = ex.getmessage(); } 

email (smtp) store , forward protocol, @ time of sending, can't tell destination email address non-existant, can find out once message gets final destination server.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -