2017-02-21 46 views
2

我使用這個代碼從我的網站發送電子郵件(來自這裏https://help.1and1.com/hosting-c37630/scripts-and-programming-languages-c85099/aspnet-c39624/send-an-e-mail-using-aspnet-a604246.html)發送來自網站的電子郵件不生成html?

//create the mail message 
MailMessage mail = new MailMessage(); 
//set the FROM address 
mail.From = new MailAddress(from); 
//set the RECIPIENTS 
mail.To.Add(to); 
//enter a SUBJECT 
mail.Subject = subject; 
//Enter the message BODY 
mail.Body = body; 
//set the mail server (default should be smtp.1and1.com) 
SmtpClient smtp = new SmtpClient("smtp.1and1.com"); 
//Enter your full e-mail address and password 
smtp.Credentials = new NetworkCredential("[email protected]", "Password"); 
//send the message 
smtp.Send(mail); 

的電子郵件將不生成的HTML。因此,而不是一個鏈接顯示它將有一個鏈接的實際代碼等。

我在做什麼錯?

+0

你在每一行的意見....我將不包括那些在現實的代碼,如果我是你。如果該行是自我解釋的,則不需要評論。你基本上在重新調整代碼已經說過的內容。如果線路不清楚或意外,我只會評論它。 – mason

回答

4

您必須添加以下行:

mail.IsBodyHtml = true; 
+0

謝謝!有用! –

相關問題