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
Adnan SunelwalaAdnan Sunelwala 

Not receiving email using sendEmail method

hi,

I am new to Salesforce and trying to build app 'Build a Conference Management App'. I had written a simple class to send email in my previous trailhead modules and was able to receive email then but for some reason not receiving any email now.

Could anyone please help track the issue?

public with sharing class  EmailManager {
    //Public Method
        public static 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.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }
  }

I am trying to test above method by writing below code using 'Execute Anonymous Window' 

String address = 'adnansun2002@yahoo.co.in';
String subject = 'Speaker Confirmation';
String body = 'Thank you for speaking at the conference.';
EmailManager.sendMail(address, subject, body);


 
Best Answer chosen by Adnan Sunelwala
Adnan SunelwalaAdnan Sunelwala
Issue resolved.

Popular email service providers such as Gmail and Yahoo email servers are blocking emails forwarded from salesforce.com IP addresses.

Came to know about this through Setup-->Email Administration-->Test Deliverability.

All Answers

Bryan JamesBryan James
Hi Adnan,
I just ran your code exactly as is and it worked flawlessly for me. Have you made sure to check your junkmail or junkmail filter to see if its getting hung up there?
Amit Chaudhary 8Amit Chaudhary 8
Your code look good to me. Please check your email id once again. Please check below post for more information
1) http://amitsalesforce.blogspot.in/search/label/Email

Let us know if this will help you

Thanks
Amit Chaudhary
Nayana KNayana K
Goto setup-> search deliverability -> set access level to All Email...
Adnan SunelwalaAdnan Sunelwala
All,  thanks for response. I use to receive email with same piece of code a month back when I initially wrote this as a part of trailhead module. Now when I intend to reuse it in an app, for strange reason it is not working.

Is there any governor limit for sending emails from developer org?

@Bryan James - I have checked my junk/spam folders unfortunately it is not present.
@Amit Chaudhary 8 - Email id is correct. I have tried with few other ids as well and it doesn't work.
@Nayana K - It is already set to 'All Email'. 
Adnan SunelwalaAdnan Sunelwala
Issue resolved.

Popular email service providers such as Gmail and Yahoo email servers are blocking emails forwarded from salesforce.com IP addresses.

Came to know about this through Setup-->Email Administration-->Test Deliverability.
This was selected as the best answer
Jagjeet Singh 13Jagjeet Singh 13
Hi Adnan, 
Your code worked absolutely fine. But when I ran executed the same flow multiple time I got the limit error : SINGLE_EMAIL_LIMIT_EXCEEDED, Email limit exceeded: [] . So definitely there is a governor limit on SingleEmailMessage. 
Please refer the link : https://developer.salesforce.com/forums/?id=906F0000000AgPFIA0 
Hope this solves your problem. 
Let me know if you are still facing any other issues.
Please mark this as a best answer.
Thanks!
Ritu Khatri 3Ritu Khatri 3
Hi ,
Exactly the mails are getting blocked on yahoo and gmail if you will try with some other domain its working absolutely fine