本文介绍了我尝试但这段代码不起作用请任何帮助我我的问题{" SMTP服务器需要安全连接或客户端未经过身份验证。服务器响应是:5.5.1身份验证...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 protected void btnSend_Click(object sender, EventArgs e)
    {
        using (MailMessage mailMessage = new MailMessage())
    {
        mailMessage.From = new MailAddress("[email protected]");
        mailMessage.Subject = txtSubject.Text.Trim();
        mailMessage.Body = txtBody.Text.Trim();
        mailMessage.IsBodyHtml = true;
        mailMessage.To.Add(new MailAddress(txtTo.Text.Trim()));
        List<httppostedfile> files = (List<httppostedfile>)Cache[this.Key];
        foreach (HttpPostedFile file in files)
        {
            mailMessage.Attachments.Add(new System.Net.Mail.Attachment(file.InputStream, Path.GetFileName(file.FileName), file.ContentType));
        }
 
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com";
        smtp.EnableSsl = true;
        System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
        NetworkCred.UserName = mailMessage.From.Address;
        NetworkCred.Password = "<password>";
        smtp.UseDefaultCredentials = true;
        smtp.Credentials = NetworkCred;
        smtp.Port = 587;
        smtp.Send(mailMessage);
    }
    Cache.Remove(this.Key);
    Response.Redirect(Request.Url.AbsoluteUri);
}</password></httppostedfile></httppostedfile>

推荐答案

smtp.UseDefaultCredentials = false;



希望有所帮助:)


Hope it helps :)


smtp.UseDefaultCredentials = false;
System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
NetworkCred.UserName = mailMessage.From.Address;
NetworkCred.Password = "<password>";
smtp.Credentials = NetworkCred;


这篇关于我尝试但这段代码不起作用请任何帮助我我的问题{&quot; SMTP服务器需要安全连接或客户端未经过身份验证。服务器响应是:5.5.1身份验证...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 19:38