2

Acumatica では、通知を使用して一部の電子メールを自動化できます。私のシナリオでは、従業員が何かをする必要があることを知る必要があるなど、特定の条件がトリガーされたときに、特定されていない (設定されていない) 時間に電子メールを送信する必要があるプロセスを作成しています。

このロジックをシステムに組み込んでいます。これが発生したときに電子メールを送信する方法のコード サンプルを探しています。

電子メール テンプレートを使用しますが、コードで偉業を達成する必要があります。acumatica の電子メール クラスを呼び出して、次のような必要な情報を渡すだけのクラスがあればいいのにと思います。

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

サンプルコードをいただければ幸いです。

4

2 に答える 2

1

これを行う方法の例を示す KB 記事があることがわかりました。このシナリオでは、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));

    }
于 2015-03-25T20:57:36.710 に答える