VB .Net Sending email using Gmail account

余生长醉 提交于 2019-12-08 06:58:26

问题


Why does this timeout?

Dim s As New SmtpClient
s.Host = "smtp.gmail.com"
s.Port = 465
s.EnableSsl = True
s.Timeout = 5000
s.Credentials = New NetworkCredential("my.name@gmail.com", "mypassword")

Dim m As New MailMessage
m.To.Add("my.name@gmail.com")
m.From = New MailAddress("my.name@gmail.com")
m.Body = "Test Message"
m.Subject = "Test Subject"
s.Send(m)

These settings come straight from my Outlook Express test setup, and it can send fine.

Set really long timeout = does nothing

Change port numbers to 587 or 25 = does nothing

One thought: Outlook Express has a "My server requires authentication" option, which I couldn't see an obvious equivalent for with SmtpClient. Could it be related to that?

Thanks in advance

Dave

--Trindaz on Fedang #vb.net-smtp


回答1:


Edit: You might need to add the following line: s.UseDefaultCredentials = False before the line starting with s.Credentials...

Do you have a firewall or some kind of anti-virus program running that might be blocking the connections?

A good place to start is to just do a simple connect from the command line.

telnet smtp.gmail.com 465

Note, depending on Windows version you might have to enable the telnet client first, see this link for details.




回答2:


You have to go into your gmail account and turn on access for less secure apps and change the port to 587



来源:https://stackoverflow.com/questions/3615674/vb-net-sending-email-using-gmail-account

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!