當前位置:名人名言大全網 - 短信平臺 - 如果郵箱需要ssl加密訪問 請問如何用c#發郵件

如果郵箱需要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;

}

不明請追問