使用gmail设置发送邮件时出现Smtp错误



我正在使用Gmail设置发送邮件,我收到了一个类似"的错误;发送邮件失败"并且InnerException为"异常";无法从传输连接读取数据:net_io_connectionclosed">

我的项目框架是.Net 4.8,程序设计语言vb,操作系统是Windows 11。

Gmail帐户设置需要更改吗?

我尝试过的:

Imports System.Net
Imports System.Net.Mail
Public Class Form1

Public Shared Function ServerCertificateValidationCallback(ByVal sender As Object, ByVal cert As System.Security.Cryptography.X509Certificates.X509Certificate, ByVal chain As System.Security.Cryptography.X509Certificates.X509Chain, ByVal sslPolicyErrors As Net.Security.SslPolicyErrors) As Boolean
Return True
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.SystemDefault Or SecurityProtocolType.Tls Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls12

Dim Mail As New System.Net.Mail.MailMessage
Dim smtp As New System.Net.Mail.SmtpClient
Mail.From = New MailAddress("aravind@gmail.com", "Aravind")
Mail.To.Add("aravind1@gmail.com")
Mail.IsBodyHtml = True
Mail.Subject = "Hai Testing Mail"
smtp = New SmtpClient("smtp.gmail.com", "587")
smtp.EnableSsl = True
smtp.DeliveryMethod = SmtpDeliveryMethod.Network
smtp.UseDefaultCredentials = False
smtp.Credentials = New System.Net.NetworkCredential("aravind@gmail.com", "xxxxxxxxxxx")
Dim userstate As Object = Mail
System.Net.ServicePointManager.ServerCertificateValidationCallback = AddressOf ServerCertificateValidationCallback
smtp.Send(Mail)
Catch ex As Exception
MessageBox.Show(ex.InnerException.ToString)
MessageBox.Show(ex.Message.ToString)
End Try
End Sub

终端类

注意,我尝试过使用465和25作为端口,仍然存在相同的问题。

1.端口465—错误为"0";发送邮件失败"并且InnerException为"异常";无法从传输连接读取数据:net_io_connectionclosed">

2.端口25—错误为"0";发送邮件失败"并且InnerException为"异常";无法连接到远程服务器";

还有一件事,我在另一个启用了2步验证的gmail帐户上尝试过,并且应用程序密码运行良好,我的意思是,从我的另一个帐户可以发送邮件。

尝试使用端口465端口或25端口而不是587,希望这将解决您的问题。如果您想要更多详细信息,请参阅此链接

https://kinsta.com/blog/gmail-smtp-server/

相关内容

  • 没有找到相关文章

最新更新