sending html email with CDO [resolved]
Guys
I need to send a html email using cdo but I don't want to have to use something like:
VB Code:
objMail.Body = "<html><table>"
'blah blah blah
In the past I've used something like:
VB Code:
objMail.Body = "../email.htm"
But this was in vb6 and I can't remember how I did it!
Any ideas?
Cheers
Re: sending html email with CDO
Hi,
this is the way I do it, and I think itll serve your puropse just fine.
strBody = "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">" & vbCrLf _
& "<html>" & vbCrLf _
& "<head>" & vbCrLf _
& " <title>Internal mailer example</title>" & vbCrLf _
& " <meta http-equiv=Content-Type content=""text/html; charset=iso-8859-1"">" & vbCrLf _
& "</head>" & vbCrLf _
& "<body bgcolor=""#FFFFCC"">" & vbCrLf _
& " <h2> This is what your internal mail will look like</h2>" & vbCrLf _
& " <p>" & vbCrLf _
& " This message was sent from a sample at" & vbCrLf _
& " <a href=""http://www.hello-world.com"">hello world</a>." & vbCrLf _
& " It is used to show people how to send HTML" & vbCrLf _
& " formatted email if you want this kind of format rther than plain text& vbCrLf _
& " This is what your internal to external mail ," & vbCrLf _
& "will look like, if you have any questions" & vbCrLf _
& " get in touch with us at blah balh balh." & vbCrLf _
& " <strong>" & vbCrLf _
& "mesage generated by the MSMQ and our business recoreds." & vbCrLf _
& " </strong>" & vbCrLf _
& " </p>" & vbCrLf _
& " <font size=""-1"">" & vbCrLf _
& " <p>Please address all concerns to hello [email protected].</p>" & vbCrLf _
& " <p>This message was sent to: " & strMailer & "</p>" & vbCrLf _
& " </font>" & vbCrLf _
& "</body>" & vbCrLf _
& "</html>" & vbCrLf
then use classic command to do the rest.
with response
' pre formatting
.Write "<pre>"
.Write Server.HTMLEncode(strbody)
.Write "</pre>"
end with
Set objCDOmail = Server.CreateObject("CDO.Message")
With objCDOmail
.To = strmailer
.From = strFrom
.Subject = strSubject
.HtmlBody = strBody
end with
The do the usual with the CDO.NewMail to send it... you know the rest!!!
Set objCDOmail = Nothing
seen loads around, but I work the best into this, and this is slick as.. Cant seem to get it to work with CSS though... oh well....
hope this helps
ta
kai :wave:
Re: sending html email with CDO
That is what I'm trying to avoid doing - embedding the html into the code. I want to pull in an external html file eg '../myemail.htm'
Re: sending html email with CDO
W3 Schools Example
Taken from above page:
Code:
<%
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="[email protected]"
myMail.To="[email protected]"
myMail.CreateMHTMLBody "http://www.w3schools.com/asp/"
myMail.Send
set myMail=nothing
%>
Looks like you simply use CreateMHTMLBody()
Re: sending html email with CDO
Hi,
oh ok sorry, you could like a file such as you did, but I wouldnt link it anywhereelse than in the root directory of where this file is
strmailbody = "mailbody.htm" or "//mailbody.htm"
Would have thought that'd work as its a virtual file path and the other is a root directoy file path.
not paying attention as Ive got a bit of a horror problem on at the mo...
ta
kai :wave:
Re: sending html email with CDO
Quote:
Originally Posted by Peter1
W3 Schools Example
Taken from above page:
Code:
<%
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="[email protected]"
myMail.To="[email protected]"
myMail.CreateMHTMLBody "http://www.w3schools.com/asp/"
myMail.Send
set myMail=nothing
%>
Looks like you simply use CreateMHTMLBody()
Aye, that's the ticket!
I'm sure I tried that earlier! I definitely looked at the w3schools site.
Anyways, thanks mate. Sorted