我知道如何在asp.net中发送电子邮件,但我不知道如何从网站中提取详细信息并将其放入电子邮件正文中。我正在那里建立一个购物车网站,以便将发票通过电子邮件发送给用户。请帮助。如何在asp.net中通过电子邮件发送邮件
0
A
回答
0
您可以对消息的字符串(如采购编号,金额,数量) 新线使用“\ n”和把4个空格(标签)使用“\ t”
然后你寄的字符串中的邮件功能,如:
try
{
MailMessage mail = new MailMessage();
//set the addresses
mail.From = new MailAddress("[email protected]_name.com");
mail.To.Add(send_to);
//set the content
mail.Subject = "This is an subject";
mail.Body = mail_content;
//send the message
SmtpClient smtp = new SmtpClient("127.0.0.1");
//to authenticate we set the username and password properites on the SmtpClient
smtp.Credentials = new System.Net.NetworkCredential("username", "password");
smtp.Send(mail);
}
catch (Exception ex)
{
//MessageBox.Show(ex.ToString());
}
不要忘记添加使用System.Net.Mail作为它的需要。
0
您可以使用下面的代码来生成发票:
public string GenerateInvoice(Invoice invoiceToGenerate)
{
StringBuilder invoiceHtml = new StringBuilder();
invoiceHtml.Append("<b>INVOICE : ").Append(invoiceToGenerate.InvoiceId.ToString()).Append("</b><br />");
invoiceHtml.Append("<b>DATE : </b>").Append(DateTime.Now.ToShortDateString()).Append("<br />");
invoiceHtml.Append("<b>Invoice Amt :</b> $").Append(invoiceToGenerate.Total.ToString("#.00")).Append("<br />");
invoiceHtml.Append("<br /><b>CUSTOMER CONTACT INFO:</b><br />");
invoiceHtml.Append("<b>Name : </b>").Append(invoiceToGenerate.ContactName).Append("<br />");
invoiceHtml.Append("<b>Phone : </b>").Append(invoiceToGenerate.ContactPhone).Append("<br />");
invoiceHtml.Append("<b>Email : </b>").Append(invoiceToGenerate.ContactEmail).Append("<br />");
invoiceHtml.Append("<b>Address : </b><br />").Append(invoiceToGenerate.ContactAddress1).Append("<br />");
invoiceHtml.Append(invoiceToGenerate.ContactAddress2).Append("<br />");
invoiceHtml.Append(invoiceToGenerate.ContactCity).Append(", ").Append(this.ContactStateProvince).Append(" ").Append(invoiceToGenerate.ContactZip).Append("<br />");
invoiceHtml.Append("<br /><b>SHIP TO:</b><br />");
invoiceHtml.Append("<b>Name : </b>").Append(invoiceToGenerate.ShipToName).Append("<br />");
invoiceHtml.Append("<b>Address : </b><br />").Append(invoiceToGenerate.ShipToAddress1).Append("<br />");
invoiceHtml.Append(invoiceToGenerate.ShipToAddress2).Append("<br />");
invoiceHtml.Append(invoiceToGenerate.ShipToCity).Append(", ").Append(this.ShipToStateProvince).Append(" ").Append(invoiceToGenerate.ShipToZip).Append("<br />");
invoiceHtml.Append("<br /><b>PRODUCTS:</b><br /><table><tr><th>Qty</th><th>Product</th></tr>");
// InvoiceItem should be a collection property which contains list of invoice lines
foreach (InvoiceItem invoiceLine in invoiceToGenerate.InvoiceItems)
{
invoiceHtml.Append("<tr><td>").Append(invoiceLine.Quantity.ToString()).Append("</td><td>").Append(invoiceLine.ProductName).Append("</td></tr>");
}
invoiceHtml.Append("</table>");
return invoiceHtml.ToString();
}
,那么你可以用这个方法把它列入你的电子邮件的身体像:
var mailBody = GenerateInvoice(invoiceObject);
using (MailMessage mailMessage = new MailMessage(fromEmail, toEmail, subject, mailBody))
{
mailMessage.IsBodyHtml = true;
using (SmtpClient smtpClient = new SmtpClient())
{
smtpClient.Host = "127.0.0.1";
smtp.Credentials = new System.Net.NetworkCredential("username", "password");
smtpClient.Send(mailMessage);
}
}
相关问题
- 1. ASP.NET通过电子邮件发送给多个电子邮件
- 2. 通过asp.net发送电子邮件3.5
- 3. 如何通过电子邮件发送电子邮件地址
- 4. ASP.NET发送电子邮件
- 5. 如何使用ASP.NET通过电子邮件发送文件?
- 6. GAS帮助 - 通过电子邮件发送电子邮件
- 7. 通过电子邮件发送文件
- 8. 通过Visual C++/Cli不发送邮件发送电子邮件
- 9. 如何通过邮件发送TestNG电子邮件报告
- 10. 如何通过电子邮件发送激活码?在asp.net mvc2
- 11. 在codeigniter中通过Google邮件发送电子邮件
- 12. 如何通过Ruby在Linux上的电子邮件发送电子邮件
- 13. 如何从ASP.Net发送电子邮件
- 14. 在asp.net中发送电子邮件
- 15. 在ASP.NET MVC2中发送电子邮件
- 16. 如何在HTML文件中通过PHP发送电子邮件?
- 17. 如何通过ASP.NET向成员发送批量电子邮件?
- 18. 如何通过电子邮件发送ASP.NET错误
- 19. 如何在MVC中通过电子邮件发送发票
- 20. Apache Commons电子邮件:如何通过非SMTP API发送电子邮件?
- 21. 通过mysql bash发送电子邮件
- 22. 通过Qt发送电子邮件
- 23. 通过电子邮件发送评价
- 24. 通过电子邮件发送从.net
- 25. 通过电子邮件发送PDFDocument
- 26. 通过O365发送电子邮件
- 27. 通过Gmail发送电子邮件
- 28. 发送电子邮件:通过对
- 29. 通过VBSCRIPT发送电子邮件
- 30. 通过Python发送Outlook电子邮件?
您是否使用窗体或MVC?您是否研究过如何在ASP.NET中处理“表单”数据? – 2012-04-28 23:09:23
你确定你应该建立一个电子商务网站,如果访问表单数据和字符串连接高于你的技能水平...? – 2012-04-28 23:09:47