私のvb.netフォームアプリケーションからSMTP電子メールを送信しようとしています。このコードを適用すると、以下のエラーが表示されます。私は間違って何をしていますか?System.Net.Mail.SmtpException SMTPサーバーがセキュリティ保護された接続を必要としているか、クライアントが認証されていません
コード:
Imports System.Net.Mail
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.Credentials = New _
Net.NetworkCredential("[email protected]", "mypassword")
SmtpServer.Port = 587
SmtpServer.Host = "smtp.gmail.com"
mail = New MailMessage()
mail.From = New MailAddress("[email protected]")
mail.To.Add("[email protected]")
mail.Subject = "Test Mail"
mail.Body = "This is for testing SMTP mail from GMAIL"
SmtpServer.Send(mail)
MsgBox("mail send")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class
エラー:この場合に役立ちます
System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first