2013-04-08 41 views

回答

1

您可以將電子郵件的內容放入單獨的.aspx頁面,然後將.aspx作爲電子郵件的正文發送。 例如: 創建一個SendMessage.aspx頁面,使用下面的代碼將此頁面設置爲電子郵件的主體。

string toEmail = string.Empty; 
string fromEmail = string.Empty; 
string subject = string.Empty; 
string body = string.Empty; 

toEmail = ConfigurationManager.AppSettings["ToEmail"].ToString(); 
fromEmail = ConfigurationManager.AppSettings["FromEmail"].ToString(); 
subject = "Hi There!"; 

StringWriter sw = new StringWriter(); 
HtmlTextWriter htw = new HtmlTextWriter(sw); 
Server.Execute("EmailTemplate.aspx?param1=" + optionalparam1, htw); 

MailMessage message = new MailMessage(fromEmail, toEmail, subject, sw.ToString()); 
message.IsBodyHtml = true; 
SmtpClient smtp = new SmtpClient(); 
smtp.Send(message); 
相關問題