Overview
Sending an email with asp is fairly easy, all you need is CDONTS (Collaboration Data Objects for NT Server, installed with IIS). In this article I'll show how to send emails with CDO, because it's available to everyone and components work in a very similar way.
First we have to create instance of the NewMail object.
<%
Option Explicit
Dim objCDOMail
Set objCDOMail = Server.CreateObject("CDONTS.NewMail")
%>
The methods and property's of this object are very obvious.
<%
objCDOMail.To = "somebody@somewhere.com" 'the destination
objCDOMail.From = "me@mydomain.com" 'the sender
objCDOMail.cc = "info@mydomain.com" 'carbon copy
Dim txtBody
txtBody = "This email has been sent by an asp script"
objCDOMail.Subject = "CDONTS" 'the subject
objCDOMail.Body = txtBody 'the body
objCDOMail.Send 'fire off the email
%>
So far it has been pretty easy, hasn't it? There's more.
<%
objCDOMail.AttachFile("c:\wwwroot\mysite\" & _
"MyAttachement.doc", "pricelist.doc")
objCDOMail.Bcc("blind@mysite.com")
objCDOMail.Importance = 1
%>
- The first rule defines an attachment ("PATH\TO\FILE", filename_that_appears)
- The second rule sends a blind carbon copy
- The third rule specifies the message's importance
Importance:
- 0 -> low
- 1 -> default
- 2 -> high
Thats it, I hope this article has been useful and i hope that now you will feel
confident sending automated newsletters, confirmation emails and so on.
If you are looking for a production ready, stable, easy to use ASP.NET Newsletter application, then look no further:
Faisal Khan (of Stardeveloper.com) has created a great Newsletter Application for you to download and start using today. It is easy to install, lets your users subscribe using a subscription form, provides a simple administration interface to create and send newsletters, handles the task of sending newsletters in the background using thread queues on the server, and lets users unsubscribe if they wish so.
Comments by the Author
Please post a lot of comments, as this is my first article. Tell me what you
like/dislike so I can improve my future articles.