November 21, 2024

Mind of Marcuzio

Performance tuning is the art of wasting ten days to save ten seconds.

Sending Email Through GMAIL using Classic ASP

Difficulty Level    

Here’s the code to send an email through gmail using Classic ASP. I included notes for easy customization for beginners

<%
Set Mail = CreateObject(“CDO.Message”)

Mail.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/sendusing”) = 2

Mail.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/smtpserver”) =”smtp.gmail.com”
Mail.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/smtpserverport”) = 465

Mail.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/smtpusessl”) = 1

Mail.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout”) = 60

Mail.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/smtpauthenticate”) = 1
Mail.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/sendusername”) =”username@gmail.com” ‘You can also use you email address that’s setup through google apps.
Mail.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/sendpassword”) =”yourpassword”

Mail.Configuration.Fields.Update

Mail.Subject=”Email subject”
Mail.From=”from@domain.com” ‘This has to be an actual email address or an alias that’s setup on the gmail account you used above
Mail.To=”to@domain.com”
Mail.Bcc=”someoneelse@somedomain.com” ‘Carbon Copy
Mail.Cc=”someoneelse2@somedomain.com” ‘Blind Carbon Copy

‘**Below are different options for the Body of an email. *Only one of the below body types can be sent.
Mail.TextBody=”This is an email message that’s text only.”
‘Mail.HTMLBody=”This is an email message that accepts HTML tags
‘Mail.CreateMHTMLBody “http://www.w3schools.com/asp/” ‘Sends an email which has a body of a specified webpage
‘Mail.CreateMHTMLBody “file://c:/mydocuments/email.htm” ‘Sends an email which has a body of an html file that’s stored on your computer. This MUST be on the server that this script is being served from.

‘ How to add an attachment
myMail.AddAttachment “c:\mydocuments\test.txt” ‘Again this must be on the server that is serving this script.

Mail.Send
Set Mail = Nothing
%>

About The Author