C#电子邮件
#region 电子邮件
public static bool webMail(string host, int port, string uid, string pwd, bool ssl, string from, string to, string subject, string body)
{
//string str="成功";
System.Net.Mail.SmtpClient mail = new System.Net.Mail.SmtpClient();
mail.Host = host;
mail.Port = port;
mail.Credentials = new System.Net.NetworkCredential(uid, pwd);
mail.EnableSsl = ssl;
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(from, to);
message.Body = body;
message.Subject = subject;
message.SubjectEncoding = System.Text.Encoding.GetEncoding("gb2312");
message.BodyEncoding = System.Text.Encoding.GetEncoding("gb2312");
message.IsBodyHtml = true;
try
{
mail.Send(message);
message.Dispose();
return true;
//return str;
}
catch (Exception ex)
{
message.Dispose();
return false;
//return ex.ToString();
}
}
#endregion
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步