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
kailash khandelwal
URL remains relative, generates Page not found error
The code below attaches google homepage and sends in the mail. BUT when I open the mail and click on any link it generates error message -Page not found. I noticed that the problem is with the link path. what am I missing?
Also, such a mail when recd and opened with AOL screws up the entire CSS style sheet.
set oMail = server.CreateObject("CDO.Message")
oMail.From = "automation@flynntechnology.com"
oMail.To = any@any.com"
oMail.Subject = "6432kkMessage from "
oMail.CreateMHTMLBody "http://www.google.com"
oMail.Send
set oMail = nothing
Andrea Martinez
RE: Getting an error too
I was getting the protocol error too. It simply seems the object needs a full URL to post the page: so you can't use
.CreatNHTMLBody "page.asp"
but if you use a full URL path to the page it works fine.
.CreatNHTMLBody http://www.fullurl.com/page.asp
maybe there's another way to post a page with a relative path, .. if you know please post..
Anton Hughes
Getting an error too
CDO.Message.1 (0x800C000D)
The specified protocol is unknown.
This is running on IIS5 on win200
Jay Khimani
Problem with CSS and CreateMHTMLBody
Hi there,
I'm able to send a HTML page or asp throug email, but the problem, is everytime i send a mail, some of the css class gets applied and some never. If i run the same page on browser, each gives output exactly as expected.
I'm appliying css through Link tag, and in CreateMHTMLBody, I've selected to include all the items on the webpage, to be embedded in the mail. When seeing the source of the email, i can see the content id for the CSS, but then also some of the specific classe in the page dont get applied. I also tried with inline style-sheet i.e. with <STYLE></STYLE> tag, but result was the same. If i use style attribute for each and every tag, then it works fine, but u all will agree, this is not the correct way to design a page.
Can anybody help me out of this problem...
Thanks,
Jay