BPMs for Automated Email On Employee Expenses Submitted And Approved

Here is the basic framework for What I use to send emails to someone when a new vendor is added. We have a security group named EM_NEWVENDOR and individuals in that group will receive an email when a new vendor is added to Epicor . This is triggered in a Standard Data directive with the condition block “There is at least 1 added row in the ttVendor Table”. Here is the code for the Custom Code Block

//Email Variables
string bpmEmail_to = string.Empty;
string bpmEmail_cc = string.Empty;
string bpmEmail_subject = string.Empty;
string bpmEmail_body = string.Empty;

string newVendor = string.Empty;
string newVendorID = string.Empty;
//
//
using (var txScope = IceContext.CreateDefaultTransactionScope())
{
// Get each new Record//
foreach (var rd in ttVendor.Where(rd => rd.Company == callContextClient.CurrentCompany ))
{
newVendor = rd.Name;
newVendorID = rd.VendorID;
}

//Set up Mail Message
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
            mail.From = new System.Net.Mail.MailAddress("VendorAlertDD@SnoWay.com");


//TO DO:  Get UserGroup member(s) email addresses to notify when this occurs

foreach(var em in Db.UserFile.Where(em => em.CurComp == callContextClient.CurrentCompany  && em.GroupList.Contains("EM_NEWVENDOR")) )
{
    mail.To.Add (em.EMailAddress.ToString());
    bpmEmail_to =  bpmEmail_to +"\n" + em.EMailAddress;  ///used for testing 
}

bpmEmail_subject = " A new Vendor has been added";

bpmEmail_body = "Please review the following Vendor and enter additional Information as appropriate. " + "\n" + "\n";
bpmEmail_body = bpmEmail_body + "\n" + "\n" + "Vendor ID: " + newVendorID + " , VendorName: " + newVendor;


//Set up Mail Client
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
        
            client.Port = 25;<<<<<<<<<<<<<<<<<--- I had to get this from the IT Dept
            client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;
            client.Host = ",Enter YOUR Email Host" ;
            mail.IsBodyHtml = true;
            mail.Subject = bpmEmail_subject;
            mail.Body = bpmEmail_body;
            client.Send(mail); //Remove comment when GO LIVE !! // <<<I use the following line uncommented to test
//Epicor.Customization.Bpm.InfoMessage.Publish(bpmEmail_to);//Remove line when GO LIVE !! ??

Db.Validate();
txScope.Complete();

}

I hope this helps