Check out the example on the link!
@AuraEnabled
public static EmailMsg getTemplateDetails(string templateId, String whoId, String whatId){
Messaging.SingleEmailMessage email = Messaging.renderStoredEmailTemplate(templateId, whoId, WhatId,Messaging.AttachmentRetrievalOption.METADATA_ONLY);
EmailMsg msg = new EmailMsg();
msg.subject = email.getSubject();
msg.body = email.getHtmlBody();
List<Messaging.EmailFileAttachment> attachmentList = email.fileAttachments;
List<FileAttachmentWrapper> fawList = new List<FileAttachmentWrapper>();
for(Messaging.EmailFileAttachment efa : attachmentList){
FileAttachmentWrapper faw = new FileAttachmentWrapper();
faw.attachId = efa.id;
faw.filename = efa.filename;
faw.isContentDocument=false;
fawList.add(faw);
}
for(ContentDocumentLink cdl : [Select ContentDocument.Id, ContentDocument.title, ContentDocument.fileExtension
from contentdocumentlink
where linkedEntityId=:templateId]){
FileAttachmentWrapper faw = new FileAttachmentWrapper();
faw.attachId = cdl.ContentDocument.id;
faw.isContentDocument = true;
faw.filename = cdl.ContentDocument.title+'.'+cdl.contentdocument.fileextension;
fawList.add(faw);
}
msg.fileattachments = fawList;
if(String.isblank(msg.body)){
msg.body = email.getPlainTextBody();
if(String.isNotBlank(msg.body)){
msg.body = msg.body.replace('\n', '<br/>');
}
}
return msg;
}