您可以使用DocEmailTemplateManager::sendMail()方法,而不是使用内置的SysEmailTable::sendMail()方法在发送之前替换电子邮件正文和主题中的占位符,该方法为您提供更多选项,例如具有动态的电子邮件正文表、多个电子邮件附件、使用抄送和密件抄送收件人等。
class DocEmailTemplateManager { /// <summary> /// Use this method to send an email using the provided built-in email template /// to the given recipient. /// </summary> /// <param name = "_emailId">Email Template ID</param> /// <param name = "_languageId">Language ID</param> /// <param name = "_emailToAddr">Recipient e-mail address or list of e-mail addresses</param> /// <param name = "_mappings"> /// Map(PlaceholderName (str) -> PlaceholderValue (str)). /// This is a map of placeholders and their values used in the dynamic email body. /// If null, it will be created and filled using the corresponding ETH (Email Template Handler) class. /// </param> /// <param name = "_lineMappings"> /// List of Map(PlaceholderName -> PlaceholderValue). /// This is a list of mappings for each line of the dynamic table within the email body. /// If null, it will be created and filled using the corresponding ETH class. /// </param> /// <param name = "_contextInfo"> /// Context info that can be provided for filling _mappings and _lineMappings /// with placeholders' values. /// </param> /// <param name = "_emailCcAddr">Cc e-mail address(es)</param> /// <param name = "_emailBccAddr">Bcc e-mail address(es)</param> /// <param name = "_emailAttachmentFilename">Email attachment filename (optional)</param> /// <param name = "_emailAttachmentContent">Email attachment file content (optional)</param> /// <param name = "_emailAdditionalAttachments"> /// Additional email attachments in a form: /// [ [attachmentName, [content]], [attachmentName, [content]], ...] /// </param> public static void sendMail(SysEmailId _emailId, LanguageId _languageId, str _emailToAddr, Map _mappings = null, List _lineMappings = null, container _contextInfo = conNull(), str _emailCcAddr = '', str _emailBccAddr = '', str _emailAttachmentFilename = '', container _emailAttachmentContent = conNull(), container _emailAdditionalAttachments = conNull()) { ... } }
让我们通过一个例子来看看它是如何工作的。假设您的电子邮件模板设置中有一封ID 为 CnfmOrder的电子邮件,并且您需要向客户 ( sara@gmail.com )发送一封电子邮件通知,告知其ID 为000725 的销售订单已得到确认。
您唯一需要做的就是使用适当的参数调用DocEmailTemplateManager::sendMail()方法,当然前提是您已经创建了一个自定义的 Docentric 的 ETH(电子邮件模板处理程序)类,它为您的自定义占位符。
public static void testSendEmail() { str recipient = 'sara@gmail.com'; str salesId = '000725'; str languageId = 'en-us'; str emailId = 'CnfmOrder'; // Send an email based on a template with the given emailId. DocEmailTemplateManager::sendMail(emailId, languageId, recipient, null, null, [salesId]); info(strFmt('Email based on template %1 successfully sent to %2!', emailId, recipient)); }
你可以在这里看到使用的 ETH 类应该是什么样子 >>
您可能采用的第二种方法是在发送电子邮件之前,在自定义 Docentric 的 ETH 类之外填充占位符名称->占位符值映射,如下所示。只需确保您的自定义占位符的名称与Docentric 电子邮件正文编辑器中使用的名称相同,即在 ETH 类中定义的名称。
public static void testSendEmail() { str recipient = 'sara@gmail.com'; str salesId = '000725'; str languageId = 'en-us'; str emailId = 'CnfmOrder'; // Create and fill mappings Map(PlaceholderName (str) -> PlaceholderValue (str)) outside of the ETH class. Map mappings = DocOrderConfirmEmailHandler::createAndFillMappingsFromOutside(salesId, languageId); // Send an email based on a template with the given emailId. DocEmailTemplateManager::sendMail(emailId, languageId, recipient, mappings); info(strFmt('Email based on template %1 successfully sent to %2!', emailId, recipient)); }
https://ax.docentric.com/sending-emails-using-docentric-apis/
留言评论
暂无留言