public static bool Send(string subject, string body, string to)
{
try
{
MailMessage myEmail = new MailMessage();
Encoding eEncod = Encoding.GetEncoding("utf-8");
myEmail.From = new System.Net.Mail.MailAddress("发送人邮箱", "发送人邮箱", eEncod);
myEmail.To.Add(to);//收信人邮箱
myEmail.Subject = subject;//主题
myEmail.Body = body;//内容
myEmail.BodyEncoding = Encoding.UTF8;
myEmail.Priority = System.Net.Mail.MailPriority.Normal;//优先级
myEmail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
string Password = "发送人邮箱密码";
smtp.Credentials = new System.Net.NetworkCredential(UserName, Password);
smtp.Send(myEmail);
}
catch (Exception ex)
{
throw new Exception("",ex);
}
return true;
}
{
try
{
MailMessage myEmail = new MailMessage();
Encoding eEncod = Encoding.GetEncoding("utf-8");
myEmail.From = new System.Net.Mail.MailAddress("发送人邮箱", "发送人邮箱", eEncod);
myEmail.To.Add(to);//收信人邮箱
myEmail.Subject = subject;//主题
myEmail.Body = body;//内容
myEmail.BodyEncoding = Encoding.UTF8;
myEmail.Priority = System.Net.Mail.MailPriority.Normal;//优先级
myEmail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = “smtp.qq.com”;如果主机是QQ那么该QQ在邮箱设置里面开启smtp服务,否则报不一致的错误
string UserName = "发送人邮箱帐号";string Password = "发送人邮箱密码";
smtp.Credentials = new System.Net.NetworkCredential(UserName, Password);
smtp.Send(myEmail);
}
catch (Exception ex)
{
throw new Exception("",ex);
}
return true;
}
1万+

被折叠的 条评论
为什么被折叠?



