如何创建临时电子邮件并使用Acumatica发送 [英] How to create an ad-hoc email and send it using Acumatica

查看:269
本文介绍了如何创建临时电子邮件并使用Acumatica发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In Acumatica you can use notifications to automate some emails. In my scenario, we are creating a process that will at non-specific (non-set) times need to send an email when a specific condition is triggered, such as an employee needs to know they need to do something.

我们正在将此逻辑构建到系统中,我正在寻找发生这种情况时如何发送电子邮件的代码示例。

We are building this logic into the system and I am looking for a code sample of how to send the email when this happens.

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

We will be using an email template, but need to accomplish the feat in code. I would hope there should be some kind of acumatica email class where we could just call it and pass the required info something like:

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

任何示例代码都可以

推荐答案

原来,有一个知识库文章提供了如何执行此操作的示例。
(针对我们的情况),这是经过验证的代码的最新版本,可以使用2个电子邮件模板之一发送电子邮件。

It turns out that there is a KB article that gives an example of how to do this. for our scenario, Here is a more recent version of the code that has been verified to send an email using either of 2 email templates.

    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));

    }

这篇关于如何创建临时电子邮件并使用Acumatica发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆