
Asp Email in ASP
Sending email from Classic ASP can be done using the built-in CDO.Message object, which leverages the Collaboration Data Objects (CDO) to send SMTP emails.
How to Send Email in Classic ASP
Simple Example using CDO.Message
<%Dim objEmailSet objEmail = Server.CreateObject("CDO.Message")' Set email propertiesobjEmail.From = "sender@example.com"objEmail.To = "recipient@example.com"objEmail.Subject = "Test Email from Classic ASP"objEmail.TextBody = "Hello! This is a test email sent from Classic ASP."' Configure SMTP serverobjEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 ' cdoSendUsingPortobjEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.yourserver.com"objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25' Optional: If SMTP server requires authentication' objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1' objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "your_username"' objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "your_password"objEmail.Configuration.Fields.Update' Send the emailobjEmail.SendSet objEmail = NothingResponse.Write "Email sent successfully!"%>
Explanation:
Property/Field | Purpose |
---|---|
From | Sender’s email address |
To | Recipient’s email address |
Subject | Subject of the email |
TextBody | Email body (plain text) |
smtpserver | Your SMTP server (e.g., smtp.gmail.com ) |
smtpserverport | SMTP port (usually 25, 465, or 587) |
smtpauthenticate | Set to 1 if SMTP requires authentication |
sendusername and sendpassword | Credentials for SMTP authentication |
Notes:
Make sure your SMTP server allows relay from your web server.
If using Gmail or other providers, you may need to configure SSL and ports accordingly (advanced setup).
You can also send HTML email by using
.HTMLBody
instead of.TextBody
.
Example: Sending HTML Email
objEmail.HTMLBody = "<h1>Welcome!</h1><p>This is an <b>HTML</b> email.</p>"
Want help with:
Sending email with attachments?
Sending email via Gmail SMTP with SSL?
Handling errors when sending email?