Monday, February 06, 2012 ..:: Reference » Sending site email through gmail ::.. Register  Login
   Sending email through gmail Minimize

One of the more recent changes on my home web environment was to stop processing email in house. This wasn't by choice. Comcast cut off port 25 one day. I understand and support the big picture goal of reducing spam. So, I needed to switch to an alternative handling of email. I had several gmail accounts, and a couple of those through Google Applications. We learned that Google apps lets you host email and we had already used that technique for pikespeakhabitat email and sunriseumc.com email.

It's pretty straightforward to point your DNS information at google (you can see it in the DNS on the parent page of this one). What gets a little trickier is sending site email through it. Google has also been doing things to help eliminate spam from senders. Some of this invovles using semi-obscure ways of communicating with the server.

Anyhow, enough of that. Here's vbscript that really sends email (except for user and password, which I'm removing so I don't give spammers an easy way to use my account).

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "heartbeat"
objMessage.From = "from email address"
objMessage.To = "to email address"
objMessage.TextBody = "heartbeat"

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"

'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1

'Your UserID on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "my gmail account"

'Your UserID on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/senderemailaddress") = "my gmail account"

'Your password on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "my password"

'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465

'Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True

'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

objMessage.Configuration.Fields.Update


objMessage.Send
 

With this script in place, I can invoke it at will using cscript mailtest.vbs from a command prompt.

I can also use the task scheduler from Windows Server (in admin tools) by starting program C:\windows\system32\cscript.exe with an argument of c:\mailtest.vbs. You can also debug it by adding //x to the command line: cscript c:\mailtest.vbs //x

    

Copyright 2010 by DotNetNuke Corporation   Terms Of Use  Privacy Statement
DotNetNuke® is copyright 2002-2012 by DotNetNuke Corporation