Solved

Send Email from Custom Graph

  • 2 March 2023
  • 1 reply
  • 165 views

Userlevel 2
Badge

Hi,

I’m using this link to https://asiablog.acumatica.com/2017/05/sending-notification-template-from.html no send a custom notification, but for some reason is not working, the sender.send() return an empty list. I’m using a custom graph and DAC.  The form have the ActivityIndicator equal to true. What I’m doing wrong?

This is my code. 

protected static void SendEmail(string message, PXGraph Base, CustomDAC transaction)
{
Notification notification = PXSelect<Notification,
Where<Notification.name, Equal<Required<Notification.name>>>>
.Select(Base, new object[] { "my template" });

bool sent = false;
string sError = "Failed to send E-mail.";
try
{
TemplateNotificationGenerator sender = TemplateNotificationGenerator.Create(transaction, notification.NotificationID.Value);
sender.MailAccountId = (notification.NFrom.HasValue)
? notification.NFrom.Value
: PX.Data.EP.MailAccountManager.DefaultMailAccountID;
sender.RefNoteID = transaction.Noteid;
//sender.Owner = notification.NFrom;
sender.To = notification.NTo;
sender.Body = notification.Body.Replace("((#replace#))", message);
var activitieds = sender.Send();
}
catch (Exception ex)
{
sent = false;
sError = ex.Message;
}
}

Thanks,

EV

icon

Best answer by andriikravetskyi35 3 March 2023, 15:27

View original

1 reply

Userlevel 5
Badge +1


Hi,

Maybe you don’t have Email Accounts in Acumatica, and email notification does not start its logic. 

Check System Email Accounts and Email Preferences screen, setup some testing default email account, and try again.

Your email notification you could check on processing screen SM507000 (Emails Pending Processing), but don’t click Process All, it will send all email to users😀

Method sender.Send() only adds notification to processing screen.

And last point, it is my method that sends emails and it works.

 

   public virtual void SendEmailNotification(string email, string emailBody)
        {
            var sender = new NotificationGenerator
            {
                To = email,
                Subject = string.Format(Messages.subjectString, this.Base.AppointmentRecords.Current.RefNbr, this.Base.AppointmentRecords.Current.ScheduledDateTimeBegin.ToString()),
                Body = emailBody,
                BodyFormat = EmailFormatListAttribute.Html
            };
            sender.Send();
        }


Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved