当前位置: 首页 > 知识库问答 >
问题:

ASP.NET SMTP服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.5.1需要身份验证[重复]

曹子平
2023-03-14

嗨,我知道这个问题有点多余,但我有不同的体验,这里是我的代码发送电子邮件后,创建帐户在ASP.NET

Dim newreg As MembershipUser = Membership.GetUser(context.Request("username"))
                Dim newid As Guid
                If newreg.ProviderUserKey IsNot Nothing Then
                    newid = DirectCast(newreg.ProviderUserKey, Guid)
                End If

                Dim body As String = String.Empty
                Dim reader As StreamReader = New StreamReader(context.Server.MapPath("~/Account/email.htm"))
                body = reader.ReadToEnd
                body = body.Replace("{UserName}", context.Request("username").ToString)
                body = body.Replace("{Url}", "http://wwww.123.com/Account/activate.aspx?id=" & context.Request("username").ToString & "&usertype=" & givetype(context.Request("username")) & "&actid=" & newid.ToString)

                Dim mailMessage As MailMessage = New MailMessage
                mailMessage.From = New MailAddress(ConfigurationManager.AppSettings("UserName"))
                mailMessage.Subject = "Account Activation"
                mailMessage.Body = body
                mailMessage.IsBodyHtml = True
                mailMessage.To.Add(New MailAddress(context.Request("email").ToString))
                Dim smtp As SmtpClient = New SmtpClient
                smtp.Host = ConfigurationManager.AppSettings("Host")
                smtp.EnableSsl = True
                Dim NetworkCred As System.Net.NetworkCredential = New System.Net.NetworkCredential
                NetworkCred.UserName = ConfigurationManager.AppSettings("UserName")
                NetworkCred.Password = ConfigurationManager.AppSettings("Password")
                smtp.UseDefaultCredentials = False
                smtp.Credentials = NetworkCred
                smtp.Port = Integer.Parse(ConfigurationManager.AppSettings("Port"))
                smtp.Send(mailMessage)

奇怪的是,当我在本地主机上运行该网站时,gmail允许它运行,但当我在vps上运行该网站时,gmail拒绝并给出这个错误

SMTP服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.5.1需要身份验证

任何帮助都会帮助tnx

共有1个答案

贡正诚
2023-03-14

问题是gmail阻止了发送电子邮件的请求,因为我为应用程序创建了一个密码,现在gmail没有阻止发送电子邮件的请求,希望如果有人会遇到gmail的同样问题,这会有所帮助

 类似资料: