I am working on sending out order confirmations on a web site with a shop functionality - all pretty much custom designed. I would like an email to be sent out once the order has been placed, ideally with a brief summary/overview of the ordered items.
I have managed to get to the point where the submission of the order triggers an email to be sent to the user, so that is all good. However, my question is how can I customize the email body in a way so it would include the list of ordered items?
Happy to add code from my controller, although I don't really think this is adding much value as this is more of a how-to-question rather than an issue I am encountering.
int orderID = order.ID;
var lineItems = DATADB.LineItemList.Where(x => x.OrderNumber == 0 && x.UserID == userID);
lineItems.ForEach(l => l.OrderNumber = orderID);
DATADB.SaveChanges();
// send order confirmation email
var orderConfirmation = DATADB.LineItemList.Where(x => x.OrderNumber == orderID).ToList();
var ordered = string.Join(",", lineItems);
var msg = new SendGridMessage();
msg.From = new System.Net.Mail.MailAddress("orders@freshNclean.ch", "freshNclean");
msg.AddTo(UserManager.FindById(userID).Email);
msg.Subject = "Deine Bestellung bei freshNclean";
msg.Text = "Hi " + UserManager.FindById(userID).FirstName.ToString() + "! Vielen Dank für Deine Bestellung." + ordered;
// SendGrid credentials
var credentials = new NetworkCredential(ConfigurationManager.AppSettings["SGaccount"], ConfigurationManager.AppSettings["SGpassword"]);
var transportWeb = new Web(credentials);
if (transportWeb != null)
{
transportWeb.DeliverAsync(msg);
}
else
{
Trace.TraceError("Web Transport konnte nicht generiert werden - die Nachricht wurde nicht versandt.");
Task.FromResult(0);
}