-
Notifications
You must be signed in to change notification settings - Fork 0
/
EmailSendCtrl.cls
29 lines (25 loc) · 1.08 KB
/
EmailSendCtrl.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
public class EmailSendCtrl {
private static boolean IS_SUCCESS = false;
@AuraEnabled
public static boolean sendEmail(String fname,String lname,string email){
system.debug('email id>'+email);
List<string> emaillst =new List<string>();
emaillst.add(email);
Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
message.toAddresses = emaillst;
message.optOutPolicy = 'FILTER';
message.subject = 'Salesforce lightning component for email send';
message.plainTextBody = 'Dear '+fname+ ' '+lname+' ,This is the message body.';
Messaging.SingleEmailMessage[] messages =
new List<Messaging.SingleEmailMessage> {message};
Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);
if (results[0].success) {
IS_SUCCESS=true;
} else {
IS_SUCCESS=false;
System.debug('The email failed to send: '
+ results[0].errors[0].message);
}
return IS_SUCCESS;
}
}