Bpm custom code Email

I have a post-processing bpm in Quote.CreatOrder. Goal is to have an email sent everytime time a quote is converted into a order and have an email for each line of the created order. Currently, I only get 1 line emailed per order regardless of how many lines it contains that meet the prodcode condition? For example, I have a 3 line order, 2 of the 3 lines match the product code criteria being line 1 and line 3. However, I am only getting an email for line 3, but I should be getting an email for lines 1 and 3.



Send the Email from within your code loop on OrderDtl

var mailer = this.GetMailer(async: false);
var message = new Ice.Mail.SmtpMail();
message.To.Add("ToEmail@email.com");
message.SetFrom("FromEmail@email.com");
message.SetSubject("Subject Text");
message.SetBody("Body Text");
mailer.Send(message); 
1 Like

Where in the code loop would this be placed?

If you put it here, you would get an email for each Order Line that has a matching Quote.

image

Thank you very much. One last question, how do I go about setting variables in the email section? Such as have the email subject output ordernum-orderline such as below.

image
image

OrderNum and OrderLine are integers, so you will want to convert them to strings.

message.SetSubject(OrderNum.ToString() + "-" + OrderLine.ToString());

As for the Body where it looks like you’ll have multiple pieces of data, you may want to use a string buildler.

At the top of your BPM Code, add the System.Text reference

using System.Text;

Then build your string for the body of the email.

StringBuilder body = new StringBuilder();
body.AppendLine("Order Number: " + OrderNum.ToString());
body.AppendLine("Order Line: " + OrderLine.ToString());
etc ... 
message.SetBody(body.ToString());