如何使用 vbscript 和远程 smtp 服务器发送电子邮件。我通过代理连接

发布于 2024-10-17 09:37:34 字数 1789 浏览 3 评论 0原文

我尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

酒浓于脸红 2024-10-24 09:37:35

由于您的代码无法连接到服务器,因此在担心您的代码之前,您是否确定可以在该端口上连接到服务器?

检查这一点的最简单方法是通过 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 have Telnet installed on your machine, just open a command prompt and type telnet 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).

指尖上得阳光 2024-10-24 09:37:35

另一件需要注意的事情(我也遇到了同样的问题)是确保适配器上的 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.

青丝拂面 2024-10-24 09:37:35

由于您使用互联网代理,因此需要使用 urlproxyserver 字段进行连接。需要做这样的事情:

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/urlproxyserver") = "yourproxy:port" 

此外,如果您使用代理但连接到本地 IP,您可能想跳过代理扫描。这可以使用 urlproxybypass Field 来完成,并且应该可以像下面这样使用

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/urlproxybypass") = "<local>"

更多信息可以在 此处找到此处。可以在此处

希望这会有所帮助。

As you are using a Internet proxy, you need to use urlproxyserver Field for connection. something like this needs to be done:

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/urlproxyserver") = "yourproxy:port" 

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 below

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/urlproxybypass") = "<local>"

More info can be found here and here. A example can be found here

hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文