function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
chandu kumarchandu kumar 

HTML Email template (with letterhead) using in triggers

I created an email alert in a trigger.it's not displaying images(custom html).how could i send email alert with HTML template with letter head.I dont think it doesn't support.is it? below is my code.
 
EmailTemplate template=[SELECT HtmlValue,Body FROM EmailTemplate WHERE Name='SpamCatchTest1'];     //custom html )(without letterhead)template

if(newCase.Origin =='Email' && newCase.SuppliedEmail !=null ) { String hbody=''; String 

plainTxtBody=''; hbody=template.HtmlValue; hbody=hbody.replace('{!Contact.Name}',k); plainTxtBody=template.Body;
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>(); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); List<String> sendTo = new List<String>(); 

sendTo.add(newCase.SuppliedEmail ); System.debug(newCase.SuppliedEmail); mail.setToAddresses(sendTo); OrgWideEmailAddress[] owea = [select Id from 

OrgWideEmailAddress where Address = 'portal.support@nexenta.com']; //mail.setReplyTo('portal.support@xxx.com'); 
List<String> ccTo = new List<String>(); ccTo.add('satheesh.thondamanti@xxx.com'); 
mail.setCcAddresses(ccTo); 
mail.setTemplateID(template.Id);//This is the template you are setting mail.setSubject('Email to Case Response'); 
//String body = 'Dear ' + Contact.FirstName + Contact.LastName + ', ';
 //body += 'Thank you for your email. Your support request cannot be processed at the moment. Support is available only for Nexenta customers who has valid support contract.For any queries on your community edition, please go to  and post your query. If you have valid support contract, please get in touch with your Nexenta sales team with purchase details to get access to Nexenta support portal.'; mail.setOrgWideEmailAddressId(owea.get(0).Id); 
mail.setHtmlBody(hbody); 
// mail.setPlainTextBody(plainTxtBody); 
// mail.setTreatTargetObjectAsRecipient(true);
 mails.add(mail); System.debug(mail); 
Messaging.sendEmail(mails); 
//Messaging.SendEmailResult[] results = Messaging.sendEmail(messages); }
Raj VakatiRaj Vakati
Try this code
 
EmailTemplate template=[SELECT HtmlValue,Body FROM EmailTemplate WHERE Name='SpamCatchTest1'];     //custom html )(without letterhead)template

if(newCase.Origin =='Email' && newCase.SuppliedEmail !=null ) { String hbody=''; String 

plainTxtBody=''; hbody=template.HtmlValue; hbody=hbody.replace('{!Contact.Name}',k); plainTxtBody=template.Body;
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>(); 
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
 List<String> sendTo = new List<String>(); 

sendTo.add(newCase.SuppliedEmail ); System.debug(newCase.SuppliedEmail); mail.setToAddresses(sendTo); 
//OrgWideEmailAddress where Address = 'portal.support@nexenta.com']; //mail.setReplyTo('portal.support@xxx.com'); 

OrgWideEmailAddress owa = [select id, DisplayName, Address from OrgWideEmailAddress  Address = 'portal.support@nexenta.com' limit 1];


List<String> ccTo = new List<String>(); ccTo.add('satheesh.thondamanti@xxx.com'); 
mail.setCcAddresses(ccTo); 
mail.setTemplateID(template.Id);//This is the template you are setting mail.setSubject('Email to Case Response'); 
//String body = 'Dear ' + Contact.FirstName + Contact.LastName + ', ';
 //body += 'Thank you for your email. Your support request cannot be processed at the moment. Support is available only for Nexenta customers who has valid support contract.For any queries on your community edition, please go to  and post your query. If you have valid support contract, please get in touch with your Nexenta sales team with purchase details to get access to Nexenta support portal.'; mail.setOrgWideEmailAddressId(owea.get(0).Id); 
mail.setTemplateID(template.Id); 
mail.setSaveAsActivity(false);
mail.setOrgWideEmailAddressId(owa.id);
allmsg.add(mail);
// mail.setPlainTextBody(plainTxtBody); 
// mail.setTreatTargetObjectAsRecipient(true);
 mails.add(mail); System.debug(mail); 
Messaging.sendEmail(mails); 
//Messaging.SendEmailResult[] results = Messaging.sendEmail(messages); }

 
chandu kumarchandu kumar
@Raj V
Thanks for quick reply. Is it HTML template with letterhead? or custom HTML??