How to send email using vbscript and remote smtp server. I am connected through a proxy
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 = "myemail@gmail.com"
objMessage.To = "tomail@gmail.com"
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 co开发者_Python百科nnect to the server" Can anyone provide me an example. I am connected to internet through proxy.
Thanks Waqar
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).
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.
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.
精彩评论