使用Gmail从asp.net发送电子邮件 [英] sending email using gmail from asp.net

查看:178
本文介绍了使用Gmail从asp.net发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图发送使用asp.net gmail邮箱

I am trying to send mail using gmail in asp.net

我的code:

using (MailMessage mm = new MailMessage(txtEmail.Text, txtTo.Text))
        {
            mm.Subject = txtSubject.Text;
            mm.Body = txtBody.Text;
            if (fuAttachment.HasFile)
            {
                string FileName = Path.GetFileName(fuAttachment.PostedFile.FileName);
                mm.Attachments.Add(new Attachment(fuAttachment.PostedFile.InputStream, FileName));
            }
            mm.IsBodyHtml = false;
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com";
            smtp.EnableSsl = true;
            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
            NetworkCredential NetworkCred = new NetworkCredential(txtEmail.Text, txtPassword.Text);
            smtp.UseDefaultCredentials = true;
            smtp.Credentials = NetworkCred;
            smtp.Port = 587;
            smtp.Send(mm);
            ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Email sent.');", true);
        }

但我得到的错误:

But i am getting error:

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at

哪里是我的错误?

where is my error?

推荐答案

您可以尝试以下建议:


  1. 尝试设置UseDefaultCredentials到假 smtp.UseDefaultCredentials = FALSE;

  2. 尝试登录到您的Gmail帐户,它可能阻止访问。

  3. 尝试使您的Gmail帐户的访问,看到这个链接了解更多信息,<一个href=\"http://email.about.com/od/gmailtips/qt/How-To-Unlock-Gmail-For-A-New-Email-Program-Or-Service.htm\" rel=\"nofollow\">http://email.about.com/od/gmailtips/qt/How-To-Unlock-Gmail-For-A-New-Email-Program-Or-Service.htm

  1. Try setting "UseDefaultCredentials" to "False" smtp.UseDefaultCredentials = false;
  2. Try logging to your Gmail account, it may be blocking the access.
  3. Try enabling access to your Gmail account, see this link for more information http://email.about.com/od/gmailtips/qt/How-To-Unlock-Gmail-For-A-New-Email-Program-Or-Service.htm

这篇关于使用Gmail从asp.net发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆