Skip to content

Instantly share code, notes, and snippets.

@jzwang-dev
Last active February 16, 2021 12:17
Show Gist options
  • Save jzwang-dev/fbf631ae384795f2408d3d13392c6609 to your computer and use it in GitHub Desktop.
Save jzwang-dev/fbf631ae384795f2408d3d13392c6609 to your computer and use it in GitHub Desktop.
[HttpPost]
public ActionResult SendOrderEmail()
{
var order = Models.OrderUtil.GetTestOrder();
string subject = "測試主旨";
string body = $@"訂單編號:{order.order_id}<br>
顧客E-mail:{order.customer_email}<br>
訂單明細:";
body += @"<table border=""1"" cellpadding=""5"">
<tr>
<th>產品</th>
<th>數量</th>
</tr>";
foreach (var detail in order.details)
{
body += $@"<tr>
<td>{detail.product_name}</td>
<td>{detail.quantity}</td>
</tr>";
}
body += "</table>";
using (SmtpClient smtp = new SmtpClient("your.smtp.server"))
{
smtp.Send(new MailMessage("noreply@jzcorp.com", order.customer_email)
{
Subject = subject,
Body = body,
IsBodyHtml = true
});
}
return View("MailSent");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment