VB .Net使用Gmail帐户发送电子邮件 [英] VB .Net Sending email using Gmail account

查看:364
本文介绍了VB .Net使用Gmail帐户发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么超时?

  Dim s As New SmtpClient 
s.Host =smtp.gmail。 com
s.Port = 465
s.EnableSsl = True
s.Timeout = 5000
s.Credentials =新建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)


这些设置直接来自我的Outlook Express测试设置,并且可以正常发送。



设置很长的超时时间=不做任何事情



更改端口号为587或25 =不做任何事情



一个想法:Outlook Express有一个我的服务器需要身份验证选项,我没有看到与SmtpClient明显的等价物。它可能与此有关吗?



预先感谢

Dave



- Fedind上的Trindaz#vb.net-smtp

解决方案

编辑:您可能需要添加以下行: s.UseDefaultCredentials = False 在以 s.Credentials ... 开头的行之前



您是否有防火墙或运行某种反病毒程序可能会阻止连接?





  telnet smtp.gmail.com 465 

开始只是从命令行执行简单连接。 code>

请注意,根据Windows版本,您可能必须先启用telnet客户端,请参阅 link 获取详细信息。


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

解决方案

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.

这篇关于VB .Net使用Gmail帐户发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆