简体   繁体   English

ASP.net联系表发送电子邮件错误

[英]ASP.net Contact Form Sending an email error

i really need help on one thing. 我真的需要一件事的帮助。 I have a website and in that website i have contact us page in which the users can contact the admin about the page or any other stuff. 我有一个网站,在该网站中,我有一个与我们联系的页面,用户可以在其中与该页面或任何其他内容的管理员联系。

The problem is when i try to render the page, it gives me an error saying 问题是当我尝试呈现页面时,它给我一个错误提示

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 

I really don't know wt to do. 我真的不知道该怎么做。 My VB behind code is : 我的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

The error is at line 23 where it is saying smtp.Send(mm) 错误在第23行显示smtp.Send(mm)

I am really in a need. 我真的很需要 Please can anyone help me. 请任何人能帮助我。

Change 更改

smtp.UseDefaultCredentials = False

your don't want to use the default credentials, you want to use the credentials you created in your code. 您不想使用默认凭据,而要使用在代码中创建的凭据。

https://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.usedefaultcredentials(v=vs.110).aspx https://msdn.microsoft.com/zh-cn/library/system.net.mail.smtpclient.usedefaultcredentials(v=vs.110).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM