You need to sign in to do that
Don't have an account?
Athira Venugopal
SingleEmailMessage() not working
I am working in Visual studio code, I am passing some values to this priceMail() method while calling from the js file. I have got the 'success' msg, but the mail is not send
@AuraEnabled
public static String priceMail(String name, String email, Double cost) {
// Create an email message object
String sMessage='';
String subject = 'Price List';
String body = 'Dear ' + name + '/n' + 'ggg' + cost;
try{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {email};
mail.setToAddresses(toAddresses);
mail.setSubject(subject);
mail.setPlainTextBody(body);
// Pass this email message to the built-in sendEmail method
// of the Messaging class
Messaging.sendEmail( new Messaging.SingleEmailMessage[] { mail });
sMessage='Success';
}
catch(Exception ex){
sMessage=ex.getLineNumber()+'\n'+ex.getCause()+'\n'+ex.getMessage()+'\n'+ex.getStackTraceString();
}
return sMessage;
}
@AuraEnabled
public static String priceMail(String name, String email, Double cost) {
// Create an email message object
String sMessage='';
String subject = 'Price List';
String body = 'Dear ' + name + '/n' + 'ggg' + cost;
try{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {email};
mail.setToAddresses(toAddresses);
mail.setSubject(subject);
mail.setPlainTextBody(body);
// Pass this email message to the built-in sendEmail method
// of the Messaging class
Messaging.sendEmail( new Messaging.SingleEmailMessage[] { mail });
sMessage='Success';
}
catch(Exception ex){
sMessage=ex.getLineNumber()+'\n'+ex.getCause()+'\n'+ex.getMessage()+'\n'+ex.getStackTraceString();
}
return sMessage;
}
Your code is correct, I've tested on my own org and it works, maybe is a miss configuration under Deliverability. In your salesforce org:
- Go to the Setup
- Type "Deliverability" into the Quick find box
- Click on Deliverability link
- Change Access Level to "All email" (just to make sure it is related)
- Finally click on save and try again.
Note I've called your method from the Execute Anonymous Apex to test itHope this help you.