You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TemplateNotificationGenerator邮件无法附加PDF,如何实现且无需自动生成文档?

解决方案

一、实现自动生成并附加PDF

要让TemplateNotificationGenerator自动生成PDF附件,需从配置和代码两方面调整:

  1. 检查通知模板配置
    在Acumatica系统的通知模板设置页面对应截图1界面:

    • 切换到「文档」标签页,勾选「附加文档」选项;
    • 选择与une_attestation实体匹配的报表模板,确保模板的输出类型设置为PDF;
    • 确认模板已启用且关联正确的数据源。
  2. 修正并完善代码
    当前代码缺少触发文档生成的关键配置,且存在重复赋值问题,调整后代码如下:

TemplateNotificationGenerator sender = TemplateNotificationGenerator.Create(une_attestation, notification.NotificationID.Value);
sender.MailAccountId = (notification.NFrom.HasValue) ? notification.NFrom.Value : PX.Data.EP.MailAccountManager.DefaultMailAccountID;
// 保留正确的实体NoteID(关联要生成PDF的对象)
sender.RefNoteID = une_attestation.NoteID;
sender.LinkToEntity = true;
sender.BAccountID = une_attestation.Atclt;
// 启用自动生成文档并附加
sender.GenerateDocument = true;
// 若通知模板未默认关联报表,可手动指定报表ID
// sender.ReportID = "ATT0001"; // 替换为实际报表模板ID

if (!string.IsNullOrEmpty(currentFilter.Usremail))
{
  sender.To = currentFilter.Usremail;
}
// 执行发送
sender.Send();
  • 删除重复的RefNoteID赋值,确保关联的是要生成PDF的实体;
  • 添加sender.GenerateDocument = true,触发自动生成文档逻辑;
  • 若通知模板未预设报表,手动指定ReportID绑定生成PDF的报表。
  1. 验证基础条件
    • 确认执行代码的用户拥有对应报表的访问权限;
    • 手动运行报表模板,验证其能正常生成PDF文件。

二、不自动生成,手动附加已存在的PDF

若需要附加已有的PDF文件而非实时生成,可通过以下方式实现:

  1. 获取PDF文件字节流
    从本地路径、Acumatica文件库或其他存储源读取PDF的字节数据:
// 示例1:从本地文件读取
byte[] pdfBytes = System.IO.File.ReadAllBytes(@"C:\Files\ExistingAttestation.pdf");

// 示例2:从Acumatica的实体附件中读取
// PX.SM.FileInfo existingFile = PXNoteAttribute.GetFile(Base, une_attestation, "对应文件的NoteID");
// byte[] pdfBytes = existingFile.BinData;
  1. 将PDF添加为邮件附件
    创建FileInfo对象并通过AddAttachment方法附加到通知:
// 创建附件对象,指定文件名与字节流
PX.SM.FileInfo pdfAttachment = new PX.SM.FileInfo(
    "Attestation.pdf", // 邮件中显示的附件名
    null,
    pdfBytes,
    null,
    true
);
// 添加到通知生成器
sender.AddAttachment(pdfAttachment);
  1. 执行邮件发送
    调用Send方法完成邮件发送,此时邮件会包含手动添加的PDF附件。

内容的提问来源于stack exchange,提问作者Xavier LARTEM

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 16:35:04