You need to sign in to do that
Don't have an account?
kevinjia1984
Format Email Body
Hi all,
I have a trigger to send emails to the email addresses listed in the "toAddresses" .And all the body message goes within the variable named 'body'. Is there any possible to format the content in the body to make it looks like a table? The following is the email sending part of my code. Thanks in advance for any help
//Static email subject information
String subject = Client_Name + '- Project Status Report - ' + Report_Date;
//Construct email body
String body = 'Report Generated by: ' + UserName + '<BR />'
+ 'Reporting For: '+ Report_Date + '<BR />' + '<BR />' +'Client Name: ' +Client_Name + '<BR />'
+ 'Overall Status: '+ Overall_Status + '<BR />' + 'Phase: ' + Phase + '<BR />'
+ 'Actions Today: '+ Actions + '<BR />'+ 'Yellow Flags: '+ Yellow_Flags+'<BR />'
+ 'Action Plan: ' + Action_Plan + '<BR />'
//Send Email
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = statusReportEmails.get(sReport.Id).split(';');
mail.setToAddresses(toAddresses);
mail.setSubject(subject);
mail.setSaveAsActivity(true);
mail.setHtmlBody(body);
HTML is a string formatted for rendering by a client. Strings do not care about their content, so it can be HTML without a problem.
All Answers
Just use the normal HTML tags: table, tbody, tr, th, td, and caption (if necessary).
Hi sfdcfox,
Thanks for your reply. But how can I realize that, the data type of body is String, I think it is not possible putting html tag in the string. Which type I should use to define body?
HTML is a string formatted for rendering by a client. Strings do not care about their content, so it can be HTML without a problem.
Thanks a lot for your help
Just one further question. How can I replace the variable in the string? Thanks
Apex Code does not support "inline variable substitution" such as PHP, Perl, Ruby, et al. You could, however, use a known pattern to do string replacements, similar to Drupal's translation system:
Many thanks for your help.