I have an issue where I can able to send and email via the 'execute anonymous apex' with no issues, but when I am doing this from my code I cannot get it to send. Also using System.debug I can see that the program is entering my email class and when I query the mail object it is instantiated and populated with all the correct values but just wont seem to send?
So I can send this from the 'execute anonymous apex' - the email sends no problem
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'[email protected]'};
mail.setToAddresses(toAddresses);
mail.setReplyTo('[email protected]');
mail.setSenderDisplayName('Otters Pocket');
mail.setSubject('Test Subject');
mail.setPlainTextBody('Test Subject');
System.debug('mail1' + mail);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
And this is the class that I created that I mentioned is being reached correctly, accepts the string parameter, instantiates the single email message, and even populates this with the values that I use here. However I cannot seem to get the email to send?
public class emailClass {
public void emailSend(String message) {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'[email protected]'};
mail.setToAddresses(toAddresses);
mail.setReplyTo('[email protected]');
mail.setSenderDisplayName('Otters Pocket');
mail.setSubject('Test Subject');
mail.setPlainTextBody('Test Subject');
System.debug('mail1' + mail);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
Also just to add I am calling this email class from an asynchronous future method.