使用启用 TLS 的服务器以 VB.Net 发送电子邮件



我正在开发用于发送启用TLS的SMTP服务器的电子邮件的应用程序,我想在Windows Server 2003上运行此应用程序。当我在窗口服务器 2012 R2 上运行相同的应用程序时,它工作得很好,但它在窗口服务器 2003 上不起作用。有什么具体原因无法在窗口服务器 2003 上运行吗?

错误:SMTP 服务器需要安全连接或客户端未经过身份验证。服务器响应为:5.7.1 客户端未通过身份验证。

我在应用程序中使用了以下代码:

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

最新更新