2013-10-22 52 views
0

您好,我知道這個問題有點多餘,但我經歷了不同的看法,這裏是我對asp.net創建帳戶後發送電子郵件asp.net SMTP服務器需要安全連接或客戶端未通過身份驗證。服務器響應爲:5.5.1需要驗證

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它拒絕並給出此錯誤

SMTP服務器需要安全連接或客戶端未驗證。服務器響應爲:5.5.1需要驗證

任何幫助會做TNX

回答

3

得到它的工作的問題Gmail是阻塞請求發送電子郵件,因爲2步驗證我所創建的密碼應用程序和現在的Gmail不會阻止發送電子郵件的請求希望這有助於如果有人會遇到與Gmail相同的問題

相關問題