Solution: Use sendEmail method as shown in the example below
public class EmailController {
    public static void sendEmail() {
        List<String> lstToAddress = new List<String>();
        lstToAddress.add(UserInfo.getUserEmail()); //Add email to whom email needs to be sent
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        email.setToAddresses(lstToAddress);
        email.setSubject('Test Email'); // Give subject of the Email
        String body='Email Content'; // content of the email
        email.setPlainTextBody(body);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[]{email});
        System.debug('Email Sent');
    }
}
Call the method from developer console using below code
EmailController.sendEmail();
Output:
Go through the resource https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_classes_email_outbound_single.htm to learn more details.



 
 
 
No comments:
Post a Comment