๐Ÿ’ป Classic ASP โ€“ Logic & Scripting
Estimated reading: 4 minutes 38 views

๐Ÿ“ง Classic ASP โ€“ Email Handling โ€“ Send Emails Using CDOSYS and SMTP

๐Ÿงฒ Introduction โ€“ What Is Email Handling in Classic ASP?

Email handling in Classic ASP allows your web applications to send automated emailsโ€”like contact form submissions, user confirmations, or admin notificationsโ€”using SMTP and CDOSYS (Collaboration Data Objects). With Classic ASP and VBScript, you can connect to any SMTP server and send messages in plain text or HTML format.

๐ŸŽฏ In this guide, youโ€™ll learn:

  • How to send emails using CDOSYS in Classic ASP
  • Configure SMTP settings (localhost or external)
  • Handle form data and email it to recipients
  • Use plain text and HTML email formats with examples

๐Ÿ“ค Basic CDOSYS Email Sending Example

<%
Dim mail
Set mail = Server.CreateObject("CDO.Message")

mail.Subject = "Test Email"
mail.From = "your_email@example.com"
mail.To = "recipient@example.com"
mail.TextBody = "This is a test message from Classic ASP."

' Configure SMTP settings
mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.yourserver.com"
mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
mail.Configuration.Fields.Update

mail.Send
Set mail = Nothing
%>

๐Ÿงช Output:
An email is sent from your_email@example.com to recipient@example.com.


๐Ÿ“ฉ Handling Email Form Submission

๐Ÿ“„ contact.asp โ€“ Form Page

<form method="post" action="sendmail.asp">
  Name: <input type="text" name="username"><br>
  Email: <input type="text" name="useremail"><br>
  Message:<br>
  <textarea name="usermessage"></textarea><br>
  <input type="submit" value="Send">
</form>

๐Ÿ“„ sendmail.asp โ€“ Processing and Sending Email

<%
Dim name, email, message
name = Request.Form("username")
email = Request.Form("useremail")
message = Request.Form("usermessage")

Dim mail
Set mail = Server.CreateObject("CDO.Message")

With mail
    .Subject = "New Contact Form Message"
    .From = email
    .To = "admin@example.com"
    .TextBody = "Name: " & name & vbCrLf & _
                "Email: " & email & vbCrLf & _
                "Message: " & message

    ' SMTP Config
    .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.yourserver.com"
    .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    .Configuration.Fields.Update
    .Send
End With

Set mail = Nothing

Response.Write "Email Sent Successfully!"
%>

๐Ÿ’ก Sending HTML Emails

mail.HTMLBody = "<h2>Welcome!</h2><p>This is a <b>HTML</b> message.</p>"

Set HTMLBody instead of TextBody to format the email using HTML.


๐Ÿ” Using SMTP Authentication (Optional)

mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "your_smtp_user"
mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "your_smtp_pass"

๐Ÿ” Common CDOSYS Field Configuration

FieldPurpose
sendusing = 2Use network (SMTP)
smtpserverYour SMTP host
smtpserverportPort (default is 25 or 587)
sendusername / sendpasswordAuth credentials
smtpauthenticate0 = None, 1 = Basic
smtpusessl (set to true)Use SSL for secure emails

โš ๏ธ Common Issues & Solutions

IssueSolution
โ€œSendUsingโ€ or โ€œBad Gatewayโ€ errorsCheck SMTP server address, port, and credentials
Email not receivedCheck spam folder; verify From/To domains
ASP error 500Confirm correct syntax and that CDOSYS is enabled in IIS

๐Ÿ“˜ Best Practices for Email Handling

โœ… Do:

  • Sanitize form inputs before using in email
  • Use HTMLBody for rich formatting
  • Use Configuration.Fields.Update before sending

โŒ Avoid:

  • Using user-supplied input directly in headers (security risk)
  • Hardcoding credentials in production code
  • Skipping error handling in live environments

๐Ÿ“Œ Summary โ€“ Recap & Next Steps

Email handling in Classic ASP is made possible via CDOSYS and a properly configured SMTP server. Whether you’re processing a form or sending welcome messages, Classic ASP gives you the tools to automate email delivery securely and flexibly.

๐Ÿ” Key Takeaways:

  • Use CDOSYS via Server.CreateObject("CDO.Message")
  • Configure SMTP with .Configuration.Fields
  • Use TextBody or HTMLBody for message content

โš™๏ธ Real-world Use Cases:

  • Contact form submission notifications
  • Password reset and login confirmation emails
  • Admin alerts for order or feedback processing

โ“ FAQs โ€“ Classic ASP Email Handling


โ“ Do I need IIS to send email in Classic ASP?
โœ… Yes. Classic ASP requires IIS and CDOSYS (enabled by default) to send emails.


โ“ Can I send emails via Gmail SMTP?
โœ… Yes, with port 587, smtpauthenticate = 1, and smtpusessl = true. Make sure less secure apps are allowed or use an app password.


โ“ Whatโ€™s the difference between TextBody and HTMLBody?
โœ… TextBody sends plain text. HTMLBody allows formatting, styles, and clickable links.


Share Now :

Leave a Reply

Your email address will not be published. Required fields are marked *

Share

๐Ÿ“ง Classic ASP โ€“ Email Handling

Or Copy Link

CONTENTS
Scroll to Top