Skip to main content

Unit: https://trailhead.salesforce.com/content/learn/modules/apex_database/apex_database_intro

I completed the code, trying the instance method, and the static method. Both methods returned the info that it was successful, but I received no emails. 

 

Here is my static method code... 

public class EmailManager {

// Public method

public static void sendMail(String address, String subject, String body) {

// Create an email message object

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

String[] toAddresses = new String[] {address};

mail.setToAddresses(toAddresses);

mail.setSubject(subject);

mail.setPlainTextBody(body);

// Pass this email message to the built-in sendEmail method

// of the Messaging class

Messaging.SendEmailResult[] results = Messaging.sendEmail(

new Messaging.SingleEmailMessage[] { mail });

// Call a helper method to inspect the returned results

inspectResults(results);

}

// Helper method

private static Boolean inspectResults(Messaging.SendEmailResult[] results) {

Boolean sendResult = true;

// sendEmail returns an array of result objects.

// Iterate through the list to inspect results.

// In this class, the methods send only one email,

// so we should have only one result.

for (Messaging.SendEmailResult res : results) {

if (res.isSuccess()) {

System.debug('Email sent successfully');

}

else {

sendResult = false;

System.debug('The following errors occurred: ' + res.getErrors());

}

}

return sendResult;

}

}

Here is the Execute Window:

EmailManager.sendMail('***@zohomail.com', 'Trailhead Tutorial', '123 body');

Here is a snippet of the Debug Only log result.. Apex Classes - EmailManager - email not received

It is not in the spam folder. 

The deliverability test works - I receive that email.

I checked settings somewhere on the deliverability - they were okay. 

Ideas??

 

Thanks

Gary Pryzner

7 risposte
  1. 7 giu 2023, 02:26

    Good idea, Ravindra. I have been so busy with work that I haven’t been able to get to this. Not meaning to seem like I’m ignoring everyone. 

     

    I did try some of the other suggestions. But for some reason I cannot create a gmail account. If it’s not working because of email settings, then it’s better to learn to change settings. It should send to any email. I will try a new playground next chance I get.