[英]ASP.net Contact Form Sending an email 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
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.Mail.SmtpException: 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
Source Error:
Line 21: smtp.Credentials = NetworkCred
Line 22: smtp.Port = 587
Line 23: smtp.Send(mm)
Line 24: lblMessage.Text = "Email Sent SucessFully."
Line 25: End Sub
Source File: C:\Users\user\Desktop\ContactUsForm\VB.aspx.vb Line: 23
我真的不知道該怎么做。 我的VB背后的代碼是:
Imports System.Net
Imports System.Net.Mail
Partial Class VB
Inherits System.Web.UI.Page
Protected Sub btnSend_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim mm As New MailMessage("sender@gmail.com", "reveiver@gmail.com")
mm.Subject = txtSubject.Text
mm.Body = "Name: " & txtName.Text & "<br /><br />Email: " & txtEmail.Text & "<br />" & txtBody.Text
If FileUpload1.HasFile Then
Dim FileName As String = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName)
mm.Attachments.Add(New Attachment(FileUpload1.PostedFile.InputStream, FileName))
End If
mm.IsBodyHtml = True
Dim smtp As New SmtpClient()
smtp.Host = "smtp.gmail.com"
smtp.EnableSsl = True
Dim NetworkCred As New System.Net.NetworkCredential()
NetworkCred.UserName = "sender@gmail.com"
NetworkCred.Password = "senderpassword"
smtp.UseDefaultCredentials = True
smtp.Credentials = NetworkCred
smtp.Port = 587
smtp.Send(mm)
lblMessage.Text = "Email Sent SucessFully."
End Sub
End Class
錯誤在第23行顯示smtp.Send(mm)
我真的很需要 請任何人能幫助我。
更改
smtp.UseDefaultCredentials = False
您不想使用默認憑據,而要使用在代碼中創建的憑據。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.