function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KevinsanKevinsan 

Can Bounce email show some error message in Contact detail page?

I have a custom field which has a lookup relationship with contact.
And I created a mail alert to send email to the contact's email address.
I want to know if some error message can be showed on Contact detail page when sending email failed?
And has anyway to verify the email address correctness before / during the mail alert run
Best Answer chosen by Kevinsan
GhanshyamChoudhariGhanshyamChoudhari
You can use below code in anonymous execution window 
 
private static boolean IS_SUCCESS = false;
list < Contact > conList = [Select Id, Name, email, Description, owner.name From contact where owner.name = 'Ghanshyam Choudhari'
    limit 1
];
List < String > emailList = new List < String > ();
for (Contact c: conList) {
    emailList.add(c.Email);
}

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

message.toAddresses = emailList;
system.debug('emailList2' + message.toAddresses);

message.subject = 'Salesforce lightning component for email send';
message.plainTextBody = 'Dear  ,This is the message body.';
Messaging.SingleEmailMessage[] messages =
    new List < Messaging.SingleEmailMessage > {
        message
    };
Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);
contact connew = new contact();
connew.id = conList[0].Id;
system.debug('connew.id@@@' + connew.id);
if (results[0].success) {
    IS_SUCCESS = true;
    connew.Description = 'Email Sent successfully';
    update connew;
} else {
    IS_SUCCESS = false;
    connew.Description = results[0].errors[0].message;
    System.debug('The email failed to send: ' +
        results[0].errors[0].message);
    update connew;
}
system.debug('IS_SUCCESS@@@' + IS_SUCCESS);