0

嗨,我知道这个问题有点多余,但我的体验有所不同这是我在 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)

奇怪的是,当我在 localhost 上运行网站时,gmail 允许它,但是当我在 vps 上运行网站时,它拒绝并给出此错误

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

任何帮助都会做 tnx

4

1 回答 1

3

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

于 2013-10-23T00:12:13.717 回答