Send ASP emails via GMAIL

Posted last year, at the end of February by Dave.
Categories: ASP, VBScript, Snippets.
Post Views: 3,550 Views.

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)
  1.  
  2.         ‘ Send emails via GMail
  3.         ‘ www.irishdeveloper.com
  4.  
  5.         Dim iSubject : iSubject = "Test Email"
  6.         Dim iSendTo : iSendTo = "Someone <someone@somewhere.com>"
  7.         Dim iFrom : iFrom = "YOUR NAME <YOUR_EMAIL@gmail.com>"
  8.        
  9.         Dim smtpUserName : smtpUserName = "YOUR_EMAIL_ADDRESS"
  10.         Dim smtpPassword : smtpPassword = "YOUR_PASSWORD"
  11.        
  12.         ‘ ##DO NOT EDIT BELOW THIS LINE ##
  13.         Const cdoSendUsingPickup = 1 ‘Send message using the local SMTP service pickup directory.
  14.         Const cdoSendUsingPort = 2 ‘Send the message using the network (SMTP over the network).
  15.         Const cdoAnonymous = 0 ‘Do not authenticate
  16.         Const cdoBasic = 1 ‘basic (clear-text) authentication
  17.         Const cdoNTLM = 2 ‘NTLM
  18.        
  19.         Set objMessage = CreateObject("CDO.Message")
  20.                 objMessage.Subject = iSubject
  21.                 objMessage.From = iSendFrom
  22.                 objMessage.To = iSendTo
  23.                 objMessage.TextBody = iMessage
  24.        
  25.                 ‘==This section provides the configuration information for the remote SMTP server.
  26.                 objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  27.                 objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
  28.                 objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
  29.                 objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = LCase(smtpUserName)
  30.                 objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = smtpPassword
  31.                 objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
  32.                 objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
  33.                 objMessage.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 120
  34.                 objMessage.Configuration.Fields.Update
  35.                 ‘==End remote SMTP server configuration section==
  36.                
  37.                 objMessage.Send
  38.         Set objMessage = Nothing
  39.  

Last 5 posts in ASP

Share and Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
    del.icio.usDe.lirio.usdiggFurlRedditYahooMyWeb

2 comments. Print Print Email Email Download a PDF version of this post. PDF
, ,  

Ireland SEO Marketing » Introducing The Irish Developer IRELAND

Pingback on March 19th, 2007 .

[…] Send ASP emails via GMAIL […]

Paul Watkins UNITED STATES

Comment on September 12th, 2007 .

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

Leave a comment

Comments can contain some xhtml. Names and emails are required (emails aren't displayed), url's are optional.




Note: This post is over a year and a half old. You may want to check later in this blog to see if there is new information relevant to your comment.

It took a bunch of illegal immigrants locked in a basement, 1.376 seconds to make this page.