Skip to content

Send email using apex

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'user@acme.com'};
String[] ccAddresses = new String[] {'smith@gmail.com'};
mail.setToAddresses(toAddresses);
mail.setCcAddresses(ccAddresses);
mail.setReplyTo('support@acme.com');
mail.setSenderDisplayName('Salesforce Support');
mail.setSubject('New Case Created : ' + case.Id);
mail.setBccSender(false);
mail.setUseSignature(false);
mail.setPlainTextBody('Your Case: ' + case.Id +' has been created.');
mail.setHtmlBody('Your case: ' + case.Id +' has been created.'+'To view your case click here.');