Last active
February 16, 2021 12:17
-
-
Save jzwang-dev/fbf631ae384795f2408d3d13392c6609 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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