我想发送电子邮件,但它给了我一个错误。
我有这个代码:
Sub sendMail(ByVal title As String, ByVal content As String)
Dim SmtpServer As New SmtpClient("smtp.gmail.com", 25)
SmtpServer.Credentials = New Net.NetworkCredential("name@gmail.com", "password")
Dim mail As New MailMessage("name@gmail.com", "name@gmail.com", title, content)
SmtpServer.Send(mail)
End Sub
我有一个尝试调用这个方法的 try catch,它不起作用,所以 catch 运行,我得到了这些异常:
System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. b6sm3176487lae.0 - gsmtp
为什么我会收到这个错误?我该如何解决?
最佳答案
Gmail 在端口 465 上使用 SMTP over SSL。
尝试做:
Dim SmtpServer As New SmtpClient("smtp.gmail.com", 465)
...
SmtpServer.EnableSsl = True
...
关于vb.net - 如何在 vb.net 中发送 Gmail 电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18153542/