【问题标题】:How to create an ad-hoc email and send it using Acumatica如何创建临时电子邮件并使用 Acumatica 发送
【发布时间】:2015-03-25 16:48:51
【问题描述】:

在 Acumatica 中,您可以使用通知来自动发送一些电子邮件。 在我的场景中,我们正在创建一个流程,当触发特定条件(例如员工需要知道他们需要做某事)时,该流程需要在非特定(非设定)时间发送电子邮件。

我们正在将这个逻辑构建到系统中,我正在寻找一个代码示例,说明如何在这种情况下发送电子邮件。

我们将使用电子邮件模板,但需要在代码中完成这一壮举。 我希望应该有某种 acumatica 电子邮件类,我们可以在其中调用它并传递所需的信息,例如:

PX.Common.email.Send(params)...

任何示例代码将不胜感激。

【问题讨论】:

    标签: erp acumatica


    【解决方案1】:

    这里我想介绍发送电子邮件的简短版本:

    using PX.Objects.EP;
    using PX.Data.EP;
    **...**
    
    var sender = new NotificationGenerator
    {
    
        To = "someone@example.com",
        Subject = $"Subject information {DateTime.Now:d}",
        Body = "Body of message",
        BodyFormat = EmailFormatListAttribute.Text
    };
    
    sender.Send();
    

    【讨论】:

    • 如何传入将用于去令牌化的电子邮件模板信息或实体对象?
    • Acumatica 有模板机制,但我没有从代码角度搜索如何使用它
    • 谢谢,我可以调查一下。
    【解决方案2】:

    事实证明,有一篇知识库文章给出了如何执行此操作的示例。 对于我们的场景,这是一个更新版本的代码,已经过验证,可以使用 2 个电子邮件模板中的任何一个发送电子邮件。

        private void mSendEmail(string toEmail, int? emailTemplateID, long? noteid, string source, string toDisplayName)
        {
            bool sent = false;
            string sError = "Failed to send E-mail.";
            POOrder porec = poOrder.Select(noteid);
            EPExpenseClaim eprec = epExpense.Select(noteid);
    
            try
            {
                Notification rowNotification = PXSelect<Notification,
                                                  Where<Notification.notificationID, Equal<Required<Notification.notificationID>>>>.Select(this, emailTemplateID);
    
                if (rowNotification == null)
                    throw new PXException(PXMessages.Localize("Notification Template for Escalation is not specified."));
    
                if (String.IsNullOrEmpty(toEmail))
                    throw new PXException(PXMessages.Localize("E-mail is not specified for Escalation Employee. Name=[" + toDisplayName +"]"));
                if (source == "PO")
                {
                    var sender = TemplateNotificationGenerator.Create(porec, rowNotification.NotificationID.Value);
                    sender.MailAccountId = rowNotification.NFrom.HasValue ?
                                           rowNotification.NFrom.Value :
                                           PX.Data.EP.MailAccountManager.DefaultMailAccountID;
    
                    sender.To = toEmail;
                    IEnumerable<EPActivity> epActivityArray = sender.Send();
                    if (epActivityArray.Count() > 0)
                    { sent = true; }
                }
                if (source == "EP")
                {
                    var sender = TemplateNotificationGenerator.Create(eprec, rowNotification.NotificationID.Value);
                    sender.MailAccountId = rowNotification.NFrom.HasValue ?
                                           rowNotification.NFrom.Value :
                                           PX.Data.EP.MailAccountManager.DefaultMailAccountID;
    
                    sender.To = toEmail;
                    IEnumerable<EPActivity> epActivityArray = sender.Send();
                    if (epActivityArray.Count() > 0)
                    { sent = true; }
                }
            }
            catch (Exception Err)
            {
                sent = false;
                sError = Err.Message;
            }
    
            if (!sent)
                throw new PXException(PXMessages.Localize(sError));
    
        }
    

    【讨论】:

    • 如果其他人有解决方案,请在此处添加,以便大家学习。谢谢
    • 这里也是知识库文章的链接。 partner.acumatica.com/…
    猜你喜欢
    • 1970-01-01
    • 2020-05-05
    • 1970-01-01
    • 1970-01-01
    • 2021-11-04
    • 2011-04-09
    • 2011-08-20
    • 1970-01-01
    • 2012-01-04
    相关资源
    最近更新 更多