發送Mail(帶Table)


添加 using System.Web.Mail;

#region Build html Talbe
   System.Text.StringBuilder tableStr=new StringBuilder();
   tableStr.Append("<TABLE id='Table1' style='Z-INDEX: 102; LEFT: 104px; WIDTH: 700px; POSITION: absolute; TOP: 24px; HEIGHT: 104px' cellSpacing='0' cellPadding='1' width='700' border='1'>");
   tableStr.Append("<TR bgcolor='#99ffff'><TD borderColor='#6600ff' style='HEIGHT: 40px'>ModelName</TD><TD borderColor='#6600ff' style='HEIGHT: 40px'>Customer</TD>");
   tableStr.Append("<TD borderColor='#6600ff' style='HEIGHT: 40px'>周次</TD><TD borderColor='#6600ff' style='HEIGHT: 40px'>Quantity</TD></TR>");
   tableStr.Append("<TR bgcolor='#99ffff'><TD borderColor='#6600ff' style='HEIGHT: 40px'>" + this.Txt_ModelName.Text.Trim().ToUpper() + "</TD>");
   tableStr.Append("<TD borderColor='#6600ff' style='HEIGHT: 40px'>" + this.Txt_Customer.Text.Trim() + "</TD><TD borderColor='#6600ff' style='HEIGHT: 40px'>" + this.Cbox_Week.SelectedValue.ToString() + "</TD>");
   tableStr.Append("<TD borderColor='#6600ff' style='HEIGHT: 40px'>" + this.Txt_Quantity.Text.Trim() + "</TD>");
   tableStr.Append("</TR></TR></TABLE>");
   #endregion

MailMessage mesg = new MailMessage();
   mesg.From = "web_admini";
   mesg.To=emailaddress;
   mesg.Subject ="業務送樣計劃維護新增";
   mesg.Body = "Dear All:"+"<br>"+"<br>"+"以下列出的是業務送樣計劃維護新增情況:" +"<br>"+ tableStr.ToString() + "<br>"+"<a href=http://inlcnwebap01/NPTR/ target=_blank>http://inlcnwebap01/NPTR/</a>" + "<br>"+
   mesg.BodyFormat=MailFormat.Html;
   SmtpMail.SmtpServer="10.133.130.62";
   SmtpMail.Send(mesg);

原文地址:https://www.cnblogs.com/HondaHsu/p/710044.html