2

Hello i im new to this site and to salesforce
i would like to add function in my apex class so that when it executes it will send and email with a message body based on a message defined in an apex class.

3

Hi Here is how we did it with the previous guy in my company:

String messageContents = '<h1 style="font-family: Arial">Title</h1>\n' +
'<p><b>Date</b></p>\n' +
'<p><b>Timings</b><br/>
'<p><b>Agenda</b><br/>Please click <a>here</a> for the final agenda </p>\n' +
'<p>If you have any questions relating to the event please contact</a></p>\n';



OrgWideEmailAddress[] owea = [select Id from OrgWideEmailAddress 
                               where Address = 'sampleaddress@something.com'];
Messaging.reserveSingleEmailCapacity(3);
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();


if ( owea.size() > 0 ) {
mail.setOrgWideEmailAddressId(owea.get(0).Id);
}


String[] toAddresses = new String[] {email}; 
String[] bccAddresses = new String[] {'cc@emailaddresses.com'};
mail.setToAddresses(toAddresses);
mail.setBccAddresses(bccAddresses);
// Specify the address used when the recipients reply to the email. 
mail.setReplyTo('reply@email.com');

mail.setSubject('Subject Body ');
mail.setBccSender(false);
mail.setUseSignature(false);
mail.setHtmlBody(messageContents);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

You also have to set org wide addresses at
Administration Setup > Email Administration > Organization Wide Address to set which email address it sends it from

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.