0
即時通訊向我的程序添加一個功能,因此用戶可以在使用郵件時向郵件發送郵件。我的問題是我試圖發送郵件後出現錯誤「郵件無法發送」 我從Gmail端解鎖了smtp端口,所以我認爲我的代碼出了問題,但無法找到它。 這就是我的代碼Vb.Net無法發送郵件
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
If TextBox18.Text.EndsWith("@gmail.com") Then
Dim Mail As New MailMessage
Mail.Subject = (TextBox17.Text)
Mail.To.Add(TextBox16.Text)
Mail.From = New MailAddress(TextBox18.Text)
Mail.Body = (Betreff.Text)
Dim SMTP As New SmtpClient("smpt.gmail.com")
SMTP.EnableSsl = True
SMTP.Credentials = New System.Net.NetworkCredential(TextBox18.Text, password.Text)
SMTP.Port = "587"
SMTP.Send(Mail)
ElseIf TextBox18.Text.EndsWith("@buch-automation.de") Then
Dim Mail As New MailMessage
Mail.Subject = TextBox13.Text
Mail.To.Add(TextBox16.Text)
Mail.From = New MailAddress(TextBox18.Text)
Mail.Body = Betreff.Text
Dim SMTP As New SmtpClient("smtp.1und1.de")
SMTP.EnableSsl = True
SMTP.Credentials = New System.Net.NetworkCredential(TextBox18.Text, password.Text)
SMTP.Port = "993"
SMTP.Send(Mail)
End If
End Sub
末級
切換'Option Strict On'以(始終)開始。另外'smpt'應該是'smtp' –
您還需要授予您的Gmail帳戶從第三方應用程序(基本上不承認)發送電子郵件的權限。鏈接在這裏https://www.google.com/settings/security/lesssecureapps –
我寫道,我解鎖了一切gmail方:) –