2012-02-14 75 views
0

私の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

Error Message

答えて

0

を参照してください。

SmtpServer.EnableSSL= true 
-1

を追加し、私は、これが最後の年だった知っているが、私は5分前に、私は同じ問題を持っていたとして、私は答えを公開しなければならないと思いました。

基本的にログイン資格情報が正しくないため、変更する必要があります。

また、前回のお返事をいただきありがとうございます。私はSSL暗号化(私はLOLを望んでいます)で電子メールを送信できるようにしています。

2
  1. ログインとパスワードが正しいかどうかを確認してください。
  2. SmtpServer.EnableSsl = trueを使用します。
  3. デフォルトでは、資格情報(ユーザーとパスワード)を使用してアクセスできなくなりました。このページに移動するには、https://www.google.com/settings/security/lesssecureappsと「セキュリティ保護されていないアプリケーションを有効にする」が必要です。詳細はこちら:https://support.google.com/accounts/answer/6010255
関連する問題