Emailing an ASP/HTML page

This is a tutorial I requested in the past, and have been asked several times if I found any info on it.  Well, here it is - short but sweet!  Very helpful for those who want to design a nice page to email out as a newsletter.

After requesting this tutorial, I eventually found the information and would like to share it with other users.

I'm going to give the short version, but there are so many other fabulous tutorials on this site that I'm sure once you have the basics of how to do this you can build on the lesson and get creative.

Basically, to email an html page using asp, have the page created and give it a name (lets call it "my_newsletter.asp"). In this example our page is going to reside on the root with the page you are using to call it, however you can use this same code to call a page residing on a different server. You can even make the page dynamic, because I will show you how to pass a variable to the page you are calling.

Without wasting too much time, here's the code...

Dim objMail2 'declare the variable

Set objMail2 = Server.CreateObject("CDO.Message") 'create your server object - CDO.Message

With objMail2 'here begins the mailing info

.To = "mailto@yourcustomer.com" 'whoever is receiving the email
.CC = "yourself@yourself.com" 'or whoever else you would like to CC
.From = "info@yourcompany.com" 'self explanatory
.Subject = "Our Newsletter" 'or whatever you would like the subject to be
.CreateMHTMLBody "my_newsletter.asp" 'this is our baby, seems so simple, doesnt it?
.Send 'send it off...

End With 'end the mailing info
Set objMail2 = Nothing 'kill the object

To send a page from another server, just use the address...

...other code
.CreateMHTMLBody "http://yourcompany.com/my_newsletter.asp
...other code

To pass a variable with the Create, just declare your variable,

dim varCustomerNumber
varCustomerNumber = 24 'you determine this

and pass it with the code

...other code
.CreateMHTMLBody "my_newsletter.asp?CustomerNumber=" & varCustomerNumber
...other code

Pretty basic, but hopefully it is enough to get you started. I have used this code without fail on a testing server running XP Pro, a testing server running Windows 2000 Advanced Server, and it currently runs on a site hosted by a company running Windows 2000 Server.

Comments

Sending to multiple people

January 17, 2003 by Gareth Pointon

This is great, but can you please tell me if you can make it send to every email address in the database automaticly.

Thanks

Gazz

How to get it working on Advance Server 2000?

January 20, 2003 by stephen deere
I can send using CDONTS anyone know how to get the example above working on Advance Server 2000 On our server am getting CDO.Message.1 error '800c000d' The specified protocol is unknown. /control/userdetail/mail2.asp, line 12

getting same error

February 7, 2003 by Christian Talbot

I'm getting same error

CDO.Message.1 (0x800C000D)
The specified protocol is unknown.

Running on IIS 5 on xp. Anyone got any ideas?

trouble when forwarding the email

February 21, 2003 by Dave Bevan

I can get this script to run great but have problems when the client receives the email and then tries to forward it to someone else.

The client sees the email fine but the forwarded email has all the images replaced by just one image from the original email. The SRC references in the forwarded emails are all pointing to the URL specified in the CreateMHTMLBody link, rather than looking for the image location on the server.

Any ideas on how to fix this?

See all 9 Comments

You must me logged in to write a comment.