使用 VB.net 2010 向 Gmail 帐户发送电子邮件

Sending E-mail to Gmail account using VB.net 2010

我在尝试让我的程序的用户向我的 Gmail 帐户发送电子邮件时遇到问题,这是我的设置:

这是我的代码:

Imports System.Net.Mail

Public Class Form1
Private Sub TextBox2_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles txtBody.TextChanged
    lblCharCount.Text = String.Format("Letter Count: {0}", txtBody.Text.Length)
End Sub

Private Sub btnSend_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSend.Click
    If YourEmailTextBox.Text <> "" AndAlso txtBody.Text <> "" Then
        Dim message As New MailMessage
        Dim smtp As New SmtpClient
        message.To.Add(YourEmailTextBox.Text.Trim())
        message.From = New MailAddress(YourEmailTextBox.Text, "heading")
        message.Subject = txtSubject.Text
        message.Body = txtBody.Text
        smtp.Host = "smtp.gmail.com"
        smtp.Port = "587"
        smtp.EnableSsl = True
        smtp.Credentials = New Net.NetworkCredential("MyGmailAccount@gmail.com", "MyPassword")
        Try
            smtp.Send(message)
            MsgBox("your message has been sent")

        Catch ex As Exception
            MsgBox(ex.Message)
            Exit Sub
        End Try
    Else
        MsgBox("Please enter a message into the body and the email address of the recipient", MsgBoxStyle.Information)
    End If
End Sub
End Class

这就是问题所在:

求助...

看不到错误框后面的内容,但您可能没有正确设置 smtp.Credentials。这是一个示例:http://www.codeproject.com/Articles/20546/How-to-Send-Mails-from-your-GMAIL-Account-through

另见:Gmail Error :The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required