SMTP发送邮件的简单实现

public static bool Send(string sendTo, string subject, string body)
{
return Send(sendTo, subject, body, false);
}

public static bool Send(string sendTo, string subject, string body, bool isHTML)
{
bool result = false;
IPHostEntry ipe = Dns.GetHostEntry(Dns.GetHostName());
IPAddress ipa = ipe.AddressList[0];

//本机的SMTP服务器

SmtpClient client = new SmtpClient(ipa.ToString());
string password = ConfigurationManager.AppSettings[ipa.ToString()];
client.Credentials = new NetworkCredential("administrator", password);


//
// SmtpClient client = new SmtpClient("smtp.163.com");//邮件服务器
//client.Credentials = new NetworkCredential("cccdddppp@163.com", "密码");


MailMessage msg = new MailMessage("Manage@Tjy.net", sendTo);
msg.SubjectEncoding = msg.BodyEncoding = Encoding.GetEncoding("gb2312");
msg.IsBodyHtml = isHTML;
msg.Subject = subject;
msg.Body = body;
// MailAddress from = new MailAddress("service@carhappy.com.cn");
// MailAddressCollection to = new MailAddressCollection();
try
{
client.Send(msg);
result = true;
}
catch (Exception)
{

result = false;
}
return result;
}

原文地址:https://www.cnblogs.com/zihunqingxin/p/3059353.html