通过Smtp发送电子邮件

时间:2014-12-13 19:01:29

标签: asp.net smtpclient

我无法发送邮件,例外情况“发送邮件失败”
我该怎么做才能纠正这些代码?

MailMessage mailMessage = new MailMessage("yourmail@mail.com", ToEmail);
StringBuilder sbEmailBody = new StringBuilder();
sbEmailBody.Append("<b>Registration Approval for</b></br>");
sbEmailBody.Append(InstituteName + "<br/><br/>");
sbEmailBody.Append("Thanks for your registration ");
sbEmailBody.Append("<br/>");

mailMessage.IsBodyHtml = true;

mailMessage.Body = sbEmailBody.ToString();
mailMessage.Subject = "Confirmation Mail!";
SmtpClient smtpClient = new SmtpClient("smtp.mail.com", 587);

smtpClient.Credentials = new System.Net.NetworkCredential()
{
    UserName = "yourmailn@mail.com",
    Password = " "
};

smtpClient.EnableSsl = true;
smtpClient.Send(mailMessage);

0 个答案:

没有答案