You need to sign in to do that
Don't have an account?
Ryan O'Sullivan
Converting a SingleEmailMessage to an Attachment
Hey,
I am trying to find a way to create a SingleEmailMessage using a template, send the email out but also take the filled in body ( the template body but with all the merge fields filled in) convert that to a blob and use that to make an attachment on the related Contract object.
Any Advice?
I am trying to find a way to create a SingleEmailMessage using a template, send the email out but also take the filled in body ( the template body but with all the merge fields filled in) convert that to a blob and use that to make an attachment on the related Contract object.
Any Advice?
// Render the Email into a string in order to save it as an attachment on the Contract
List<Messaging.RenderEmailTemplateBodyResult> templateResults =
Messaging.renderEmailTemplate(call.oContract.Delinquency_Recipient_1__c, call.oContract.Id,
new String[]{emailTempQuery[0].body});
// Go through results, and create attachments from them
for(Messaging.RenderEmailTemplateBodyResult result:templateResults){
if(result.getSuccess()){
// Render was successful
Blob attachmentBlob = Blob.valueOf(result.getMergedBody());
newAttachments.add(new Attachment(Body = attachmentBlob, ParentId = call.oContract.Id,
Name = emailTempQuery[0].name));
} else {
System.debug('Failed to render email template');
}
}
All Answers
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.Body = attch.Body;
efa.FileName = attch.Name;
efa.ContentType = attch.ContentType
Thanks,
BM
// Render the Email into a string in order to save it as an attachment on the Contract
List<Messaging.RenderEmailTemplateBodyResult> templateResults =
Messaging.renderEmailTemplate(call.oContract.Delinquency_Recipient_1__c, call.oContract.Id,
new String[]{emailTempQuery[0].body});
// Go through results, and create attachments from them
for(Messaging.RenderEmailTemplateBodyResult result:templateResults){
if(result.getSuccess()){
// Render was successful
Blob attachmentBlob = Blob.valueOf(result.getMergedBody());
newAttachments.add(new Attachment(Body = attachmentBlob, ParentId = call.oContract.Id,
Name = emailTempQuery[0].name));
} else {
System.debug('Failed to render email template');
}
}