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
Elmer UytingcoElmer Uytingco 

Getting Started with Apex Exercise - Unable to Receive Email


Unable to receive email from Email Manager in exercise although the log below indicates email was sent succesfully.  Any ideas on how to troubleshoot?

Here is the code also:

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;
    }

}

LOG:
====
37.0 APEX_CODE,FINEST;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
Execute Anonymous: //EmailManager em = new EmailManager();
Execute Anonymous: EmailManager.sendMail('uytingcoel@gmail.com', 'Trailhead Tutorial', '123 body');
08:12:27.1 (1693955)|USER_INFO|[EXTERNAL]|005610000010YwX|uytingcoel@yahoo.com|Eastern Standard Time|GMT-04:00
08:12:27.1 (1721463)|EXECUTION_STARTED
08:12:27.1 (1730849)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
08:12:27.1 (2046370)|HEAP_ALLOCATE|[72]|Bytes:3
08:12:27.1 (2124668)|HEAP_ALLOCATE|[77]|Bytes:152
08:12:27.1 (2168187)|HEAP_ALLOCATE|[342]|Bytes:408
08:12:27.1 (2194894)|HEAP_ALLOCATE|[355]|Bytes:408
08:12:27.1 (2216264)|HEAP_ALLOCATE|[467]|Bytes:48
08:12:27.1 (2253417)|HEAP_ALLOCATE|[139]|Bytes:6
08:12:27.1 (2285536)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:1
08:12:27.1 (2398403)|STATEMENT_EXECUTE|[1]
08:12:27.1 (2402986)|STATEMENT_EXECUTE|[2]
08:12:27.1 (2407023)|HEAP_ALLOCATE|[2]|Bytes:20
08:12:27.1 (2410857)|HEAP_ALLOCATE|[2]|Bytes:18
08:12:27.1 (2413144)|HEAP_ALLOCATE|[2]|Bytes:8
08:12:27.1 (2478268)|HEAP_ALLOCATE|[50]|Bytes:5
08:12:27.1 (2505766)|HEAP_ALLOCATE|[56]|Bytes:5
08:12:27.1 (2515779)|HEAP_ALLOCATE|[64]|Bytes:7
08:12:27.1 (2546886)|SYSTEM_MODE_ENTER|false
08:12:27.1 (2584411)|HEAP_ALLOCATE|[2]|Bytes:5
08:12:27.1 (3957848)|HEAP_ALLOCATE|[2]|Bytes:4
08:12:27.1 (3964998)|HEAP_ALLOCATE|[2]|Bytes:5
08:12:27.1 (3988092)|METHOD_ENTRY|[1]|01p610000089QAq|EmailManager.EmailManager()
08:12:27.1 (3996337)|STATEMENT_EXECUTE|[1]
08:12:27.1 (4004467)|STATEMENT_EXECUTE|[1]
08:12:27.1 (4013806)|METHOD_EXIT|[1]|EmailManager
08:12:27.1 (4055378)|METHOD_ENTRY|[2]|01p610000089QAq|EmailManager.sendMail(String, String, String)
08:12:27.1 (4090284)|VARIABLE_SCOPE_BEGIN|[4]|address|String|false|false
08:12:27.1 (4122577)|VARIABLE_ASSIGNMENT|[4]|address|"uytingcoel@gmail.com"
08:12:27.1 (4133343)|VARIABLE_SCOPE_BEGIN|[4]|subject|String|false|false
08:12:27.1 (4137861)|VARIABLE_ASSIGNMENT|[4]|subject|"Trailhead Tutorial"
08:12:27.1 (4140882)|VARIABLE_SCOPE_BEGIN|[4]|body|String|false|false
08:12:27.1 (4144239)|VARIABLE_ASSIGNMENT|[4]|body|"123 body"
08:12:27.1 (4155079)|STATEMENT_EXECUTE|[4]
08:12:27.1 (4157138)|STATEMENT_EXECUTE|[6]
08:12:27.1 (4247692)|VARIABLE_SCOPE_BEGIN|[6]|mail|Messaging.SingleEmailMessage|true|false
08:12:27.1 (4362488)|VARIABLE_ASSIGNMENT|[6]|mail|"common.api.soap.wsdl.SingleEmailMessage@efa978"|0x943ea19
08:12:27.1 (4369535)|STATEMENT_EXECUTE|[7]
08:12:27.1 (4411988)|HEAP_ALLOCATE|[7]|Bytes:4
08:12:27.1 (4487206)|VARIABLE_SCOPE_BEGIN|[7]|toAddresses|List<String>|true|false
08:12:27.1 (4523565)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
08:12:27.1 (4550008)|VARIABLE_ASSIGNMENT|[7]|toAddresses|{"s":1,"v":["uytingcoel@gmail.com"]}|0x1cd2b297
08:12:27.1 (4555391)|STATEMENT_EXECUTE|[8]
08:12:27.1 (4610574)|STATEMENT_EXECUTE|[9]
08:12:27.1 (4658050)|STATEMENT_EXECUTE|[10]
08:12:27.1 (4679999)|STATEMENT_EXECUTE|[13]
08:12:27.1 (4704696)|HEAP_ALLOCATE|[14]|Bytes:4
08:12:27.1 (4827799)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
08:12:27.1 (4882464)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
08:12:27.1 (74154700)|EMAIL_QUEUE|[13]|subject: Trailhead Tutorial, bccSender: false, saveAsActivity: true, useSignature: true, toAddresses: [uytingcoel@gmail.com], plainTextBody: 123 body,
08:12:27.1 (74280802)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
08:12:27.1 (74335953)|HEAP_ALLOCATE|[13]|Bytes:8
08:12:27.1 (74371094)|VARIABLE_SCOPE_BEGIN|[13]|results|List<Messaging.SendEmailResult>|true|false
08:12:27.1 (74490967)|VARIABLE_ASSIGNMENT|[13]|results|"common.apex.runtime.impl.ScalarList@762a45b4"|0x2174fb9
08:12:27.1 (74504199)|STATEMENT_EXECUTE|[17]
08:12:27.1 (74542513)|METHOD_ENTRY|[17]|01p610000089QAq|EmailManager.inspectResults(List<Messaging.SendEmailResult>)
08:12:27.1 (74583048)|VARIABLE_SCOPE_BEGIN|[21]|results|List<Messaging.SendEmailResult>|true|false
08:12:27.1 (74645265)|VARIABLE_ASSIGNMENT|[21]|results|"common.apex.runtime.impl.ScalarList@762a45b4"|0x2174fb9
08:12:27.1 (74655397)|STATEMENT_EXECUTE|[21]
08:12:27.1 (74657423)|STATEMENT_EXECUTE|[22]
08:12:27.1 (74668379)|VARIABLE_SCOPE_BEGIN|[22]|sendResult|Boolean|false|false
08:12:27.1 (74678513)|HEAP_ALLOCATE|[22]|Bytes:5
08:12:27.1 (74685915)|VARIABLE_ASSIGNMENT|[22]|sendResult|true
08:12:27.1 (74984390)|HEAP_ALLOCATE|[28]|Bytes:5
08:12:27.1 (75155948)|HEAP_ALLOCATE|[28]|Bytes:4
08:12:27.1 (75194225)|VARIABLE_SCOPE_BEGIN|[28]|res|Messaging.SendEmailResult|true|false
08:12:27.1 (75250996)|VARIABLE_ASSIGNMENT|[28]|res|"common.api.soap.wsdl.SendEmailResult@762a4595"|0x16972a5
08:12:27.1 (75258727)|STATEMENT_EXECUTE|[28]
08:12:27.1 (75296793)|STATEMENT_EXECUTE|[29]
08:12:27.1 (75299001)|STATEMENT_EXECUTE|[30]
08:12:27.1 (75305905)|HEAP_ALLOCATE|[30]|Bytes:23
08:12:27.1 (75358958)|USER_DEBUG|[30]|DEBUG|Email sent successfully
08:12:27.1 (75377076)|HEAP_ALLOCATE|[28]|Bytes:5
08:12:27.1 (75390882)|VARIABLE_ASSIGNMENT|[28]|res|null|
08:12:27.1 (75395724)|STATEMENT_EXECUTE|[38]
08:12:27.1 (75401673)|METHOD_EXIT|[17]|01p610000089QAq|EmailManager.inspectResults(List<Messaging.SendEmailResult>)
08:12:27.1 (75410404)|METHOD_EXIT|[2]|01p610000089QAq|EmailManager.sendMail(String, String, String)
08:12:27.1 (75423531)|SYSTEM_MODE_EXIT|false
08:12:27.95 (95395610)|CUMULATIVE_LIMIT_USAGE
08:12:27.95 (95395610)|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 0 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 1 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

08:12:27.95 (95395610)|CUMULATIVE_LIMIT_USAGE_END

08:12:27.1 (95471081)|CODE_UNIT_FINISHED|execute_anonymous_apex
08:12:27.1 (96992487)|EXECUTION_FINISHED
 
Prateek Singh SengarPrateek Singh Sengar
Hi Elmer,
Kindly check your email deliverability settings. In Access to send email it should be set to all emails.
Elmer UytingcoElmer Uytingco
HI Prateek,

Thanmk YOu for the response.  I checked the Access to send  email and it is "set to all emails".  Still getting the followng email error:

This message was created automatically by the mail system.

A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:

>>> uytingcoel@yahoo.com (Undelivered): 530 5.7.1 Authentication required

------ This is a copy of the original message, including all headers. ------

Return-Path: <uytingcoel@yahoo.com>
Received: from [10.246.204.108] ([10.246.204.108:59694] helo=na34-app2-5-phx.ops.sfdc.net)
    by mx4-phx-sp1.mta.salesforce.com (envelope-from <uytingcoel@yahoo.com>)
    (ecelerity 3.6.17.52090 r(Core:3.6.17.0)) with ESMTPS (cipher=DES-CBC3-SHA)
    id 5B/B0-32782-86B66B75; Fri, 19 Aug 2016 02:14:00 +0000
Date: Fri, 19 Aug 2016 02:14:00 +0000 (GMT)
From: Elmer Uytingco <uytingcoel@yahoo.com>
To: "uytingcoel@yahoo.com" <uytingcoel@yahoo.com>
Message-ID: <2iXUM000000000000000000000000000000000000000000000OC4WVC006YhpU2NPSMqsgv3OUhJOvw@sfdc.net>
Subject: Trailhead Tutorial
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-SFDC-LK: 00D61000000ZuSQ
X-SFDC-User: 005610000010YwX
X-Sender: postmaster@salesforce.com
X-mail_abuse_inquiries: http://www.salesforce.com/company/abuse.jsp
X-SFDC-ORGTYPE: FREE
X-SFDCOrgRelay: 00D61000000ZuSQ
X-SFDCRelayAddr: smtp.mail.yahoo.com
X-SFDCRelayPort: 25
X-SFDCTLS: 0
X-SFDC-Binding: 1WrIRBV94myi25uC
X-SFDC-EmailCategory: apiSingleMail
X-SFDC-Interface: internal

123 body

Hope you can help?

Thanks!
Elmer UytingcoElmer Uytingco
All,

It is working now!  Not sure why????

I tried several things:

1) Tried to resolve a potential "Domain" Email Problem by changing my "From" Email Address to a different one.
2) Activated/Deactivated Email Relay Service
3) Tried "Test Deliverability" with different emails; for some reason my Yahoo/Gmail was not working but my Apple and Work email worked right away.

Again, do not know why Yahoo/Gmail were not receivng any of my emails from Salesforce Emai Manager code.

 
Jess BurghJess Burgh
Hi all! Having an issue with the  sending email command. Went to execute and got this message User-added image
Not sure what I'm doing wrong.  I entered the code with a gmail email address Any help would be appreciated!