Click here to Skip to main content
Click here to Skip to main content

Tagged as

Go to top

Send Email using Classic ASP

, 3 Apr 2014
Rate this:
Please Sign up or sign in to vote.
This is a complete working example with code on how to send email using classic ASP.

Introduction

This tip explains how to send email using classic ASP. I am using gmail as relay server in this tip.

Background

I have seen a lot of people trying to send emails using classic ASP, but face some issues. Although there are lot of code snippets available, but here I am sharing a complete working ASP file that can be used to send emails.

Using the Code

In this example, I will use CDO.Message for sending email from classic ASP code. The code is tested using a Gmail account, but you can use any valid email account from any provider. The attached file is a complete working example and is tested in live setup. To test this example, you have to set the SMTP server and authentication information. Here is the explanation of the code.

To send email, first of all, create an object of CDO.Message:

dim objMail 
Set objMail = Server.CreateObject("CDO.Message") 

Set the SMTP server and authentication information:

dim smtpServer, yourEmail, yourPassword
smtpServer = "smtp.gmail.com"
yourEmail = "youremail@gmail.com"     'replace with a valid gmail account
yourPassword = "yourpassword"   'replace with a valid password for account set in yourEmail 

Replace youremail@gmail.com and yourpassword with the email id and password of a valid gmail account.

Now set the various configuration properties:

objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtpServer
objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 
objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = yourEmail
objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = yourPassword
objMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60 
objMail.Configuration.Fields.Update 

Now prepare your actual message and send email using Send method.

objMail.Subject="Application Form Registration Details"
objMail.htmlBody = "This is test message"
objMail.Send   

Points of Interest

The default port for SMTP is 25. If you are using gmail server, i.e., smtp.gmail.com, then you have to use port number 465. Whichever SMTP server you are using, set the smtpserver and smtpserverport according to that. Most people face the issue in email due to incorrect port number.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Code Help 2014
Software Developer (Senior)
India India
No Biography provided

Comments and Discussions

 
QuestionTo: PinmemberMember 1018411822-Jul-14 11:17 
AnswerRe: To: PinmemberCode Help 201422-Jul-14 19:16 
GeneralRe: To: PinmemberMember 1018411823-Jul-14 5:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140922.1 | Last Updated 3 Apr 2014
Article Copyright 2014 by Code Help 2014
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid