Apex_mail.send
apex_mail.send
is a method in Salesforce that allows you to send emails from your Apex code. Here's a brief overview:
Syntax:
ApexMail.send(String subject, String body, String[] recipients, String[] cc, String[] bcc, String fromName, String fromAddress);
Parameters:
subject
: The subject line of the email.body
: The body of the email.recipients
: An array of email addresses to send the email to.cc
: An array of email addresses to send a carbon copy (CC) to.bcc
: An array of email addresses to send a blind carbon copy (BCC) to.fromName
: The name of the sender.fromAddress
: The email address of the sender.
Example:
String subject = 'Hello from Apex!';
String body = 'This is a test email sent from Apex.';
String[] recipients = new String[] {'[email protected]', '[email protected]'};
String[] cc = new String[] {'[email protected]'};
String[] bcc = new String[] {'[email protected]'};
String fromName = 'Apex User';
String fromAddress = '[email protected]';
ApexMail.send(subject, body, recipients, cc, bcc, fromName, fromAddress);
Notes:
- Make sure to set up your email settings in Salesforce by going to Setup > Email > Email Settings.
- The
ApexMail
class is only available in Salesforce Classic. In Lightning Experience, you should use theMessaging.SingleEmailMessage
class instead. - You can also use the
ApexMail
class to send emails with attachments by using thesetAttachment
method. - Be mindful of email sending limits and best practices when sending emails from Apex code.