INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

ASP-Enabled Web Server

How to Send Email Using ASP by lottastuff
Posted: 31 Dec 02 (Edited 7 Feb 03)

This question seems to come up quite a bit, and the answer depends on which email component your web server makes available. Below is code for four widely used components as well as a simple method for determining which component you have access to (assuming it's not easiest to just ask your hosting provider):


<%
'Begin by discovering which email component your server runs:
dim objMail
set objMail = Server.CreateObject("Persits.MailSender")    'ASPEmail
set objMail = Server.CreateObject("SMTPsvg.Mailer")        'ASPMail
set objMail = Server.CreateObject("CDONTS.Newmail")    'CDONTS
set objMail = Server.CreateObject("JMail.SMTPMail")        'Jmail
%>


ONE of the above is likely to work without producing an error. Comment out the ones that don't work until you find the one that works (or you COULD just ask whoever manages your web server).

Do just the lines above until you determine which email component you have available for use. Once that's settled, eliminate all the "set objMail" lines that do not work, and add whichever block of code below corresponds to that component. In each case, a "see X for more" link is provided.

ASPEmail (Persits) example (see http://www.aspemail.com/Manual.htm for more)

<%
Set objMail = Server.CreateObject("Persits.MailSender")
objMail.Host = "mail.smtp-server.com" ' Specify a valid SMTP server
objMail.From = "sendersemail@yourdomain.com" ' Specify sender's address
objMail.FromName = "Senders Name" ' Optionally specify sender's name
objMail.AddAddress  "recipientsemail@theirdomain.com", "Optional Recipient Name" 'Specify recipient
objMail.AddCC = "someotherrecipient@somedomain.com"
objMail.AddBcc = "someotherrecipient@somedomain.com"
objMail.AddAttachment = "c:\images\cakes.gif"    'How to add an attachment
objMail.Subject = "Sending Email with  ASP using Persits"
objMail.Body = "Please disregard this email. It is only a test."
'---or---
objMail.Body = "<html><body><h1>Please disregard this email!</h1>It is only a test</body></html>"
objMail.IsHTML  = true
'--Finally, send it
objMail.Send
%>


ASPMail example (see for http://www.serverobjects.com/comp/Aspmail4.htm for more)

<%
set objMail = Server.CreateObject("SMTPsvg.Mailer")
objMail.RemoteHost = "mail.smtp-server.com" ' Specify a valid SMTP server
objMail.FromAddress = "sendersemail@yourdomain.com" ' Specify sender's address (only one)
objMail.FromName = "Senders Name" ' Optionally specify sender's name
objMail.AddRecipient  "Recipients Name", "recipientsemail@theirdomain.com"  'Specify recipient
objMail.AddCc = "Additional Recipients Name", "someotherrecipient@somedomain.com"
objMail.Bcc = "Additional Recipients Name", "someotherrecipient@somedomain.com"
objMail.AddAttachment  = "c:\images\cakes.gif"    'How to add an attachment
objMail.Subject = "Sending Email with  ASP using CDONTS"
objMail.BodyText = "Please disregard this email. It is only a test."
'---or---
objMail.BodyText = "<html><body><h1>Please disregard this email!</h1>It is only a test</body></html>"
objMail.ContentType   = "text/html"
'--Finally, send it
objMail.SendMail
%>


CDONTS example (see for http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdo/html/_denali_newmail_object_cdonts_library_.asp for more)

<%
set objMail = Server.CreateObject("CDONTS.Newmail")
objMail.From = "sendersemail@yourdomain.com" ' Specify sender's address (only one)
objMail.To = "recipientsemail@theirdomain.com"  'Use ; to seperate items in a list of recipients
objMail.Cc = "someotherrecipient@somedomain.com"
objMail.Bcc = "someotherrecipient@somedomain.com"
objMail.AttachFile  = "c:\images\cakes.gif"    'How to add an attachment
objMail.Subject = "Sending Email with  ASP using CDONTS"
objMail.Body = "Please disregard this email. It is only a test."
'---or---
objMail.Body = "<html><body><h1>Please disregard this email!</h1>It is only a test</body></html>"
objMail.BodyFormat   = 0
'--Finally, send it
objMail.Send
%>


JMAIL example (see for http://www.dimac.net/?contentKey=%7bB8B59804-C6FE-4A61-B687-6897008381F4%7d&nil=nil for more)

<%
set objMail = Server.CreateObject("JMail.SMTPMail")
objMail.ServerAddress  = "mail.smtp-server.com" ' Specify a valid SMTP server
objMail.From  = "sendersemail@yourdomain.com" ' Specify sender's address (only one)
objMail.FromName = "Senders Name" ' Optionally specify sender's name
objMail.AddRecipient  = "recipientsemail@theirdomain.com", "Recipients Name"  'email and optional recipient name
objMail.AddRecipientCC = "someotherrecipient@somedomain.com"
objMail.AddRecipientBCC = "someotherrecipient@somedomain.com"
objMail.AddAttachment = "c:\images\cakes.gif"    'How to add an attachment
objMail.Subject = "Sending Email with  ASP using CDONTS"
objMail.Body  = "Please disregard this email. It is only a test."
'---or---
objMail.AppendHTML = "<html><body><h1>Please disregard this email!</h1>It is only a test</body></html>"
objMail.BodyFormat   = 0
'--Finally, send it
objMail.Execute
%>

Back to Microsoft: ASP (Active Server Pages) FAQ Index
Back to Microsoft: ASP (Active Server Pages) Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close