Below is the code to send an ASP email via GMail’s SMTP servers. Some websites are trying to sell this (one website I found is selling it for $4.95!), but Im showing you for free. I will code a better looking one with a submit form, so watch this space. Enjoy!
Required: CDO, GMail account
Code (asp)
-
-
‘ Send emails via GMail
-
‘ www.irishdeveloper.com
-
-
Dim iSubject : iSubject = "Test Email"
-
Dim iSendTo : iSendTo = "Someone <someone@somewhere.com>"
-
Dim iFrom : iFrom = "YOUR NAME <YOUR_EMAIL@gmail.com>"
-
-
Dim smtpUserName : smtpUserName = "YOUR_EMAIL_ADDRESS"
-
Dim smtpPassword : smtpPassword = "YOUR_PASSWORD"
-
-
‘ ##DO NOT EDIT BELOW THIS LINE ##
-
Const cdoSendUsingPickup = 1 ‘Send message using the local SMTP service pickup directory.
-
Const cdoSendUsingPort = 2 ‘Send the message using the network (SMTP over the network).
-
Const cdoAnonymous = 0 ‘Do not authenticate
-
Const cdoBasic = 1 ‘basic (clear-text) authentication
-
Const cdoNTLM = 2 ‘NTLM
-
-
Set objMessage = CreateObject("CDO.Message")
-
objMessage.Subject = iSubject
-
objMessage.From = iSendFrom
-
objMessage.To = iSendTo
-
objMessage.TextBody = iMessage
-
-
‘==This section provides the configuration information for the remote SMTP server.
-
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
-
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
-
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
-
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = LCase(smtpUserName)
-
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = smtpPassword
-
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
-
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
-
objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 120
-
objMessage.Configuration.Fields.Update
-
‘==End remote SMTP server configuration section==
-
-
objMessage.Send
-
Set objMessage = Nothing
-
Last 5 posts in ASP
Share and Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
[…] Send ASP emails via GMAIL […]
Paul Watkins 
Nice script! I found a few minor issues…
1) The first part of the script declares iFrom, but objMessage is being set with iSendFrom, which does not exist
2) Comments in the script should start with ‘ not `
3) iMessage is not declared or set to anything
4) objMessage is not declared
All of this is not a big deal. I actually caught most of this when I put “Option Explicit” at the top of my test script.
I really appreciate you putting this out there - I really didn’t want to pay for the script you mentioned
FWIW, I am going to use your code in a larger script that will use Windows Task Scheduler to check the USGS percipitation readings in my town every day. If the rainfall is over 1/2 inches in a 24-hour period, I am required to inspect erosion fences; so this will email me if the USGS site near the project records rainfall exceeding 1/2 inch.
Thank you again!
Paul
It took a bunch of illegal immigrants locked in a basement, 0.726 seconds to make this page.