You need to sign in to do that
Don't have an account?
Terence Viban
Send Single Email in Apex
Hi all,
I am sending a single email from Apex code. Although I do not have any erros, the email doesn't get sent. As you can see from the code snippet, it is pretty uncomplicated. Wanted to do a test send before I get to the complicated stuff. There are not error messages but the email doesn't get sent. Any ideas???
Messaging.Singleemailmessage mail = new Messaging.Singleemailmessage();
mail.setToAddresses(new String[] {'terence1122@gmail.com'});
mail.setReplyTo('noreply@privatebudget.com');
mail.setSenderDisplayName('Private Budget App');
mail.setSubject('Private Budget records for ' + Date.today().month() + ' ' + Date.today().year());
mail.setBccSender(false);
mail.setUseSignature(false);
mail.setPlainTextBody('This is a test');
system.debug('@@@@ sendEmail - mail : ' + mail);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
The sytem debug produces the following
@@@@ sendEmail - mail : Messaging.SingleEmailMessage[getBccAddresses=null;getCcAddresses=null;getCharset=null;getDocumentAttachments=null;getFileAttachments=null;getHtmlBody=null;getInReplyTo=null;getOrgWideEmailAddressId=null;getPlainTextBody=This is a test;getReferences=null;getTargetObjectId=null;getTemplateId=null;getToAddresses=(terence1122@gmail.com);getWhatId=null;isUserMail=false;]
I am working on the dev org and executing the class which sends the mail from execute anonymous.
Thanks
I am sending a single email from Apex code. Although I do not have any erros, the email doesn't get sent. As you can see from the code snippet, it is pretty uncomplicated. Wanted to do a test send before I get to the complicated stuff. There are not error messages but the email doesn't get sent. Any ideas???
Messaging.Singleemailmessage mail = new Messaging.Singleemailmessage();
mail.setToAddresses(new String[] {'terence1122@gmail.com'});
mail.setReplyTo('noreply@privatebudget.com');
mail.setSenderDisplayName('Private Budget App');
mail.setSubject('Private Budget records for ' + Date.today().month() + ' ' + Date.today().year());
mail.setBccSender(false);
mail.setUseSignature(false);
mail.setPlainTextBody('This is a test');
system.debug('@@@@ sendEmail - mail : ' + mail);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
The sytem debug produces the following
@@@@ sendEmail - mail : Messaging.SingleEmailMessage[getBccAddresses=null;getCcAddresses=null;getCharset=null;getDocumentAttachments=null;getFileAttachments=null;getHtmlBody=null;getInReplyTo=null;getOrgWideEmailAddressId=null;getPlainTextBody=This is a test;getReferences=null;getTargetObjectId=null;getTemplateId=null;getToAddresses=(terence1122@gmail.com);getWhatId=null;isUserMail=false;]
I am working on the dev org and executing the class which sends the mail from execute anonymous.
Thanks
Access level should be 'All email'.
Yord Code is working Fine for me, so tere is an issue of Deliveribility Settings,
Go to: Setup -> Administer -> Email Administration -> Deliverability and set the Access level to "All email".
let us know if you have any question .
please don't Forget to Mark this as your best answer if it works fine for you
Regards,
Grazitti Team
Web: www.grazitti.com
How did you try this on your org? did you use execute anonymous as well? could this be the problem?. At this point am just guessing because I do not see why the email should not be sent. I have tried two different valid email addresses.
Thanks for your contribution
Were you able to solve this issue? I am facing the same issue. The code works from Execute Anonymous but not from apex.
The last time I ran into this problem, the reason was that the code was executed by the Automated Process user. This user doesn't have any email assigned, so I had to set it explicitly using Org-Wide Email Address:
It works in Exec Anon but not apex controller!
I have fiddled with all the settings I can see.
Messaging.sendEmail() doesn't work from controller level Apex.
Messaging.sendEmail() DOES work from trigger level Apex. (which runs at the same level as Exec Anon)
Use a trigger to send email! Templates using custom objects all work, everything!