Arb*_*tur 5 vb.net email gmail smtp
我想发送一封电子邮件,但它给了我一个错误.
我有这个代码:
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
Run Code Online (Sandbox Code Playgroud)
我有一个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
...
Run Code Online (Sandbox Code Playgroud)
试试这个 - 我知道它有效.
Dim Mail As New MailMessage
Dim SMTP As New SmtpClient("smtp.gmail.com")
Mail.Subject = "Security Update"
Mail.From = New MailAddress("name@gmail.com")
SMTP.Credentials = New System.Net.NetworkCredential("name@gmail.com", "password") '<-- Password Here
Mail.To.Add(address & "@gmail.com") 'I used ByVal here for address
Mail.Body = "" 'Message Here
SMTP.EnableSsl = True
SMTP.Port = "587"
SMTP.Send(Mail)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
38227 次 |
| 最近记录: |