Built in email handler

Hi Melanie,
Welcome!

I chose to create a custom Epicor Function for sending our notification emails, with the following parameters:

  • AddressFrom
  • AddressTo
  • AddressCC
  • AddressBCC
  • AddressReplyTo
  • Subject
  • Body

The function uses a Custom Code block, with the following code:

var notificationSettings = Db.UD10.FirstOrDefault(row => row.Company == callContextClient.CurrentCompany && row.Key1 == "NOTIFICATION" && row.Key2 == "GLOBAL");

if (string.IsNullOrWhiteSpace(AddressFrom))
{
  AddressFrom = notificationSettings.Character05;
}

var subjectPrefix = notificationSettings.Character08;
if (!string.IsNullOrWhiteSpace(subjectPrefix))
{
  Subject = subjectPrefix + " " + Subject;
}

var bodyPrefix = notificationSettings.Character09;
if (!string.IsNullOrWhiteSpace(bodyPrefix))
{
  Body = bodyPrefix + "<br><br>" + Body;
}

var mailer = this.GetMailer(async:true);
var message = new Ice.Mail.SmtpMail();

message.SetFrom(AddressFrom);
message.SetTo(AddressTo);
message.SetCC(AddressCC);
message.SetBcc(AddressBCC);
message.SetReplyTo(AddressReplyTo);
message.SetSubject(Subject);
message.SetBody(Body);

message.IsBodyHtml = true;
mailer.Send(message);

We use User Defined table 10 (UD10) to store custom settings. In this case we use it to define some ‘Prefix’ text that we prepend, such as ‘TEST’ for example, to indicate that the email came from our Test environment.

We can call this Function from BPMs, etc, or via the REST API.