I created an Email template in classic.
However, When I send this email via send test and verify merge fields I get the display as show in the HTML preview.
However, when I send the e-mail via apex I get no formatting at all and plain text.
Example of response. As you can see it has lost all formatting.
Example of APEX code.
for(test__c rta: prta ){
EmailTemplate et = [SELECT Id,Subject, Body, BrandTemplateId FROM EmailTemplate WHERE Id =: '00X1X000000MSiu'];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
string [] toaddress= New string[]{rta.Client_Global_Email_Main__c};
mail.setToAddresses(toaddress);
string subject = 'Hi ' + rta.Client_Global_Forename__c;
mail.setTemplateId(et.Id);
mail.setSenderDisplayName('Your doom');
mail.setHTMLBody(et.Body);
mail.setTreatBodiesAsTemplate(true);
mail.setSaveAsActivity(true);
mail.setUseSignature(true);
mail.setSubject(subject);
allMails.add(mail);
smsChasing(rta.Client_Global_Tel_Mobile__c, rta.Id );
}
Messaging.sendEmail(allMails);
Question) How do I send an E-mail via APEX and preserve the formatting.