Previous Article
Classic ASP, AJAX and ReCapTcha
Send Email using ASP Classic and CDOSYS
Next Article
SELECT Statement, INSERT Statement, UPDATE Statement, DELETE Statement, in ASP using Parameter's, in the combat against SQL & XSS INJECTION
Coding Article #: 26 - Published On: October 07, 2011 @ 06:29:15 AM - Last Updated on: June 20, 2012
This article has been Favorited 13 times
Join today, and add this to your favorites.
Coding Source - Share on MySpace Coding Source - Share With Facebook Coding Source - Share on Twitter Coding Source - Share on Reddit Coding Source - Share on Digg It Coding Source - Share on Stumble Upon It Coding Source - Share on Delicious
Share With Friends (Updated 6-8-2010)

Supported Files
No Files for this Article.
No Screenshot Available
Sending email using Classic ASP and the CDOSYS component that comes preinstalled in all Windows servers and operating systems. For the new 2008 Server and Windows Vista and Windows 7, you will have to download the CDOSYS component from Microsoft.

First, we need our form. With an name, email, subject, and a message field.
mailform.asp

<form method="post" action="mail.asp">
<label>Name</label>
<div><input type="text" name="name" /></div>
<label>Email</label>
<div><input type="text" name="email" /></div>
<label>Subject</label>
<div><input type="text" name="subject" /></div>
<label>Message</label>
<div><textarea name="message" rows="5" cols="60"></textarea>
<label>Submit Your Message to Us</label>
<div><input type="submit" name="submit" value="Send Mail" /></div>
</form>


Next, we need to process the form, and send out the message to the recipient (Most of the time, this is the webmaster or owner of the site).
mail.asp

<%
Dim ObjSendMail
Set ObjSendMail = CreateObject("CDO.Message")
      
'This section provides the configuration information for the remote SMTP server.
      
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Send the message using the network (SMTP over the network).
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="mail.yourserver.com"
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False 'Use SSL for the connection (True or False)
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
      
' If your server requires outgoing authentication uncomment the lines bleow and use a valid email address and password.
'ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication
'ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") ="somemail@yourserver.com"
'ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="yourpassword"
      
ObjSendMail.Configuration.Fields.Update
      
'End remote SMTP server configuration section==
 
' gets the variables from the form to use in your mail
getName = request.form("name")
getEmail = request.form("email")
getSubject = request.form("subject")
getMessage = request.form("message")
      
ObjSendMail.To = "someone@someone.net" ' Put in the email address that you want to send the message to.
ObjSendMail.Subject = getSubject
ObjSendMail.From = getEmail &"("&getName&")"
      
'Now we are sending the email body
ObjSendMail.HTMLBody = "This is the first line of your email<br />"
ObjSendMail.HTMLBody = ObjSendMail.HTMLBody &"This is the second line of your email<br />"
' Now to add your variables to your email body
ObjSendMail.HTMLBody = ObjSendMail.HTMLBody &"Message from: "&getName&"<br /> with email: "&getEmail&"<br /> with subject: "&getSubject&"<br /> With Message: <br />"&getMessage&""
'ObjSendMail.TextBody = "this is the body"
 
' Now time to send the message.    
ObjSendMail.Send
      
Set ObjSendMail = Nothing
%>
Post to Facebook about: Send Email using ASP Classic and CDOSYS