问题
I am developing application for sending an email with TLS enabled SMTP server and this application I want to run on windows server 2003. When I run this same application on window server 2012 R2 its working perfect but it wont work on window server 2003. Is there any specific reason it wont work on window server 2003?
Error: SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated.
I used below code in my application:
Public Sub sendemail()
Dim SMTPMailServer As New System.Net.Mail.SmtpClient("xyz") 'tls enabled SMTP Server Name
Dim myMail As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage("FromEmail", "ToEmail")
With myMail
.Subject = "Test Email with TLS enabled server"
.Body = "Test Body"
.Priority = Net.Mail.MailPriority.Normal
.IsBodyHtml = True
End With
SMTPMailServer.Send(myMail)
myMail = Nothing
End Sub
回答1:
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("username@gmail.com", "password")
SmtpServer.Port = 587
SmtpServer.Host = "smtp.gmail.com"
mail = New MailMessage()
mail.From = New MailAddress("YOURusername@gmail.com")
mail.To.Add("TOADDRESS")
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
来源:https://stackoverflow.com/questions/59372731/send-email-in-vb-net-with-tls-enabled-server