发送邮件asp.net

时间:2022-01-16 14:36:20
调用 
fnSendMail("1677236123@qq.com", "注册错误:" + ex.ToString() + "发生时间:" + System.DateTime.Now, "版本合一网站错误"); 
 
public void fnSendMail(string StrTo, string StrBody, string strSubjec)
    {
 
        System.Net.Mail.MailMessage onemail = new System.Net.Mail.MailMessage();
 
        string myEmail = "1416680744@qq.com"; //发送邮件的邮箱地址
 
        string myPwd = "jqftbx*****ujhfa"; //发送邮件的邮箱密码
 
        onemail.BodyEncoding = System.Text.Encoding.UTF8;
 
        onemail.IsBodyHtml = true;
 
        onemail.From = new System.Net.Mail.MailAddress(myEmail);
 
        onemail.To.Add(new System.Net.Mail.MailAddress(StrTo));
 
        onemail.Subject = strSubjec;
 
        onemail.Body = StrBody;
 
        System.Net.Mail.SmtpClient clint = new System.Net.Mail.SmtpClient("smtp.qq.com", 587);//发送邮件的服务器smtp.qq.com
 
        clint.Credentials = new System.Net.NetworkCredential(myEmail, myPwd);
 
        clint.EnableSsl = true;
 
        clint.Timeout = 15000;
 
        try { clint.Send(onemail); }
        catch (Exception ex) { }
 
    }