0

私は本当に一つのことで助けが必要です. 私はウェブサイトを持っており、そのウェブサイトには、ユーザーがページやその他のものについて管理者に連絡できるお問い合わせページがあります。

問題は、ページをレンダリングしようとすると、エラーが表示されることです

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

エラーは、smtp.Send(mm) と言っている 23 行目にあります。

私は本当に困っています。誰でも私を助けてください。

4

1 に答える 1

0

変化する

smtp.UseDefaultCredentials = False

デフォルトの資格情報を使用したくない場合は、コードで作成した資格情報を使用します。

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

于 2015-05-31T04:05:23.553 に答える