如果邮箱需要ssl加密访问 请问如何用c#发邮件
展开全部
这个是我自己做的一个QQ发邮件代码,注:ssl加密要到邮箱里发短信来获取密码(不是你的QQ密码)
代码如下:
private bool SendMail(Form2.History hsSendInfo, string warning = null)
{
try
{
string HostName = System.Net.Dns.GetHostName();
string AddressIP = string.Empty;
string SystemTime = System.DateTime.Now.ToString();
string Address = GetAddress();
MailMessage mm = new MailMessage();
mm.From = new MailAddress(hsSendInfo.Account);
mm.To.Add(hsSendInfo.Exexplain);
mm.Subject = "登录信息提醒";
mm.Body = "XX";
mm.BodyEncoding = System.Text.Encoding.UTF8;
mm.IsBodyHtml = false;
SmtpClient sc = new SmtpClient();
NetworkCredential nc = new NetworkCredential();
nc.UserName = hsSendInfo.Account;
nc.Password = hsSendInfo.Password;
sc.UseDefaultCredentials = true;
sc.DeliveryMethod = SmtpDeliveryMethod.Network;
sc.Credentials = nc;
sc.Host = "smtp.qq.com";
sc.EnableSsl = true;
sc.Send(mm);
}
catch
{
return false;
}
return true;
}
不明请追问
代码如下:
private bool SendMail(Form2.History hsSendInfo, string warning = null)
{
try
{
string HostName = System.Net.Dns.GetHostName();
string AddressIP = string.Empty;
string SystemTime = System.DateTime.Now.ToString();
string Address = GetAddress();
MailMessage mm = new MailMessage();
mm.From = new MailAddress(hsSendInfo.Account);
mm.To.Add(hsSendInfo.Exexplain);
mm.Subject = "登录信息提醒";
mm.Body = "XX";
mm.BodyEncoding = System.Text.Encoding.UTF8;
mm.IsBodyHtml = false;
SmtpClient sc = new SmtpClient();
NetworkCredential nc = new NetworkCredential();
nc.UserName = hsSendInfo.Account;
nc.Password = hsSendInfo.Password;
sc.UseDefaultCredentials = true;
sc.DeliveryMethod = SmtpDeliveryMethod.Network;
sc.Credentials = nc;
sc.Host = "smtp.qq.com";
sc.EnableSsl = true;
sc.Send(mm);
}
catch
{
return false;
}
return true;
}
不明请追问
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询