2017-02-21 47 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

谢谢!有用! –

相关问题