0

I am trying to send an email from a public visualforce. I think it isnt working because some permissions of the public profile because I tested the method from developer console and it worked perfectly. It is weird because I am not receiving any error/exception so I am a bit confused.

Similar code:

String emailMessage = '...' ;
String[] addresses = Label.EmailExample;
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(addresses);
mail.setSenderDisplayName('subject');
mail.setSubject('subject');
mail.setHtmlBody(emailMessage);
Messaging.sendEmail(new Messaging.SingleEmailMessage[]{ mail });

I also printed the email and the fields were correctly filled, same with the addresses (I didnt copied the exact code).

So I guess the custom object and field permissions are set correctly, I only can think I am missing some System permission.

So... ¿What am I missing?

Edit: Debugging SendEmailResult apparently it says isSuccess = true when I keep dont seeing the email in my inbox/spam/whatever

2
  • Can you request an email log and see if the email shows up there? That will let you know whether or not it's actually sending. Also, can you post your actual code? It's much easier to help when we see what you're actually running (or a minimal example that behaves the same way). Oct 3 '18 at 18:15
  • Email didnt show in email log, but I found the issue, I create another answer. Thanks you anyway
    – Juan Aavh
    Oct 4 '18 at 12:57
1

Issue was I was sending the email in the constructor of the VF, as you probably know, you cant use DML in the constructor of a controller. Looks like you cant send emails neither, but it doesnt create any exceptions or error as the Email Result was returning isSuccess: true.

Could be a bug after all...

Solution: use tag action="{!onload}" in the page declaration

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.