+ Start a Discussion
Benjamin ViertelBenjamin Viertel 

EmailManager.sendMail success but no Email arrives

Doing the Beginner Dev: https://trailhead.salesforce.com/content/learn/modules/apex_triggers/apex_triggers_intro?trail_id=force_com_dev_beginner

Sendmail is working with "success" in console. But no mail arrives. I tried with two email adresses.
SarvaniSarvani
Hi Benjamin,

Where exactly are you trying to give the email address ? I assume you are giving it on the trigger ExampleTrigger in line 5 like below.
EmailManager.sendMail('Exampleemail@gmail.com', 'Trailhead Trigger Tutorial', recordCount + ' contact(s) were inserted.');

Also verify if you have class with EmailManager and method sendMail as in the module link https://trailhead.salesforce.com/en/content/learn/modules/apex_database/apex_database_intro which sends an email to the address specified.

If eveyrthing is fine you may have to check email develiverability settings in the setup -> Check Setup | Email Administration | Deliverability | Access level?

Also check your spam or junk folders for the email.

Hope this helps! Please mark as best if it does

Thanks
Benjamin ViertelBenjamin Viertel
Yes, I give the email as first argument string within ' ' (I also tried without ' '). The debug messages say "email sent successfully". Where exactly can I find those Email Administration settings? I searched in Setup and in Developer Console.
Benjamin ViertelBenjamin Viertel
I found the Email setting for Deliverability. Cannot find anything strange there:
- access level: all
- activate bounce management checked
- enable compliance with standard email security mechanisms
- log activities 
- TLS setting: preferred
SarvaniSarvani
Hi Benjamin,

Did you check your spam or other folders where you usually see the salesforce emails. Also try checking the email log files. Setup-> Email log files ->Request for the email ids to which you tried sending the triggered email.

If your issue persists please paste your trigger and class as a response.

Thanks
Benjamin ViertelBenjamin Viertel

Normally, I get all the salesforce emails fine in my incoming mailbox, not in junk or elsewhere. I get emails, when I installed a package to the cunning moose account or when package installation fails, for example.

I can not find anything in junk. I tried this with two email addresses.

I have no entries under Email Logs. I tried to request logs. I now have one pending email log request (for a period of seven days). I did not receive any email on the completion of the pending request. I also don't see a log yet. I waited several minutes. 

I just came accross a trail with an email for the second time. I will post my classes from this trail. Not sure if they are the same for the original question, but the result is the same: USER_DEBUG: Email sent successfully

But no email arrived. 

public class EmailMissionSpecialist {
   public void sendMail(String address, String subject, String body) {
      Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
      String[] toAddresses = new String[] {address};
      mail.setToAddresses(toAddresses);
      mail.setSubject(subject);
      mail.setPlainTextBody(body);
      Messaging.SendEmailResult[] results = Messaging.sendEmail(
                                new Messaging.SingleEmailMessage[] { mail });
      inspectResults(results);
   }
   private static Boolean inspectResults(Messaging.SendEmailResult[] results) {
      Boolean sendResult = true;
      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;
   }
}

AND Apex Code from anonymous execution window:

 

EmailMissionSpecialist em = new EmailMissionSpecialist();
em.sendMail('benjamin.viertel@sellmore.de', 'Flight Path Change', 
   'Mission Control 123: Your flight path has been changed to avoid collision '
   + 'with asteroid 2014 QO441.');

 

 

Benjamin ViertelBenjamin Viertel

The log request finished. I can check the log. But I did not receive an email for this (which I should have). This is the line which is for the outgoing email which endet as SUCCESS in DEBUG:
 

03/13/2020 14:49:45,"A1/F8-08313-65C9B6E5",T,"benjamin.viertel@sellmore.de","benjamin.viertel=sellmore.de__0-a8mgfv56jpcs5y@ecoksl4x5birt3d2.d0mgtbilaeczrcjs.5gwtr9.3x-4xe08uag.eu29.bnc.salesforce.com","91.90.159.161",1793,0053X00000Bi7bK,"<H-C1U000000000000000000000000000000000000000000000Q74ZME00FzIaR4LXRT6GXnFJA9Ty8A@sfdc.net>",1,"307.469441","reading BANNER",,,"450 4.0.0 The connection was not accepted at this time. Please try again later.",":",unverified