I would like to send an email template ,with merge fields from case, even to a fixed address'[email protected]'.
Template:
Hi, this is case {!Case.CaseNumber}.
Code:
public void sendSingleEmailfromCustomSetting( string TemplateDeveloperName , string ToAddresses){
EmailTemplate emailTemplate = [select Id,
Body
from EmailTemplate
where DeveloperName = :TemplateDeveloperName ];
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
email.setToAddresses( toAddresses.split( '[;,]' ) );
email.setSaveAsActivity(false);
email.setTargetObjectId(?);
//Required if using a template
//Only Users, Contact or Lead allowed for targetObjectId
email.setTemplateId(emailTemplate.Id);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
}
The problem is that, in order to send a template, i should set email.setTargetObjectId that is only available for contact, lead, or user.
Is there some workaround?
I would like to use a template, avoiding building message body in apex.
Thanks in advantage for any advice.