如何使用 vbscript 和远程 smtp 服务器发送电子邮件。我通过代理连接
我尝试使用 gmail smtp 编写一个 vbscript 来发送邮件,但它不起作用,因为我通过代理连接到互联网。 下面是我的代码。
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Example CDO Message"
objMessage.From = "[email protected]"
objMessage.To = "[email protected]"
objMessage.TextBody = "This is some sample message text."
'==This section provides the configuration information for the remote SMTP server.
'==Normally you will only change the server name or IP.
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "MyUserName"
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "MyPassword"
objMessage.Configuration.Fields.Update
'==End remote SMTP server configuration section==
objMessage.Send
当我运行此代码时,它给我错误“传输无法连接到服务器” 谁能给我举个例子。我通过代理连接到互联网。
谢谢 瓦卡尔
I tried to write a vbscript to mail using gmail smtp but it is not working because I am connected to internet through proxy.
Below is my code.
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Example CDO Message"
objMessage.From = "[email protected]"
objMessage.To = "[email protected]"
objMessage.TextBody = "This is some sample message text."
'==This section provides the configuration information for the remote SMTP server.
'==Normally you will only change the server name or IP.
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "MyUserName"
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "MyPassword"
objMessage.Configuration.Fields.Update
'==End remote SMTP server configuration section==
objMessage.Send
when i am running this code it gives me error "The transport failed to connect to the server"
Can anyone provide me an example. I am connected to internet through proxy.
Thanks
Waqar
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于您的代码无法连接到服务器,因此在担心您的代码之前,您是否确定可以在该端口上连接到服务器?
检查这一点的最简单方法是通过
Telnet
。假设您的计算机上安装了Telnet
,只需打开命令提示符并输入telnet smtp.gmail.com 465
。如果失败,那么您的代码也无法执行此操作。此失败的最常见原因是防火墙阻止您使用端口 465,并且由于您提到了代理,我认为这也可能是一个问题。如果您确实设法在该端口上进行连接,请参阅此问题示例 vbscript 代码(同时建议您可以使用简单的 SMTP 命令行工具(如果效果更好))。
Since your code fails to connect to the server, before even worrying about your code, have you made sure that you can connect to the server at all on that port?
The easiest way to check this is via
Telnet
. Assuming that you haveTelnet
installed on your machine, just open a command prompt and typetelnet smtp.gmail.com 465
. If this fails, then your code can't do it either. The most common reason for this fail is due to a firewall that blocks you from using port 465 and since you mention a proxy, I'd assume that this could be a problem as well.If you do manage to connect on that port, see the accepted answer to this question for sample vbscript code (and also a suggestion that you could instead use a simple SMTP command line tool if that would work better).
另一件需要注意的事情(我也遇到了同样的问题)是确保适配器上的 DNS 设置正确。
我给了我的服务器一个静态 IP,但我猜想跳过了 DNS 服务器地址,因此无法解析任何内容。只是我的一个疏忽,但我想我会提到这一点。
One other thing to look at (I had the same issue) is make sure the DNS settings on the adapter are correct.
I gave my server a static IP but I guess skipped the DNS Server addresses so nothing could be resolved. Just an oversight on my part but thought I'd mention it.
由于您使用互联网代理,因此需要使用
urlproxyserver 字段
进行连接。需要做这样的事情:此外,如果您使用代理但连接到本地 IP,您可能想跳过代理扫描。这可以使用 urlproxybypass Field 来完成,并且应该可以像下面这样使用
更多信息可以在 此处找到 和此处。可以在此处
希望这会有所帮助。
As you are using a Internet proxy, you need to use
urlproxyserver Field
for connection. something like this needs to be done:Further, incase if you ever use a proxy but connect to a local IP,You might want to skip the proxy scan.This can be done using
urlproxybypass Field
and it should be used like this belowMore info can be found here and here. A example can be found here
hope this helps.