Results 1 to 6 of 6

Thread: sending html email with CDO [resolved]

  1. #1

    Thread Starter
    Hyperactive Member thebloke's Avatar
    Join Date
    May 2003
    Posts
    358

    Resolved 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:
    1. objMail.Body = "<html><table>"
    2. 'blah blah blah

    In the past I've used something like:

    VB Code:
    1. objMail.Body = "../email.htm"

    But this was in vb6 and I can't remember how I did it!

    Any ideas?

    Cheers
    Last edited by thebloke; Oct 27th, 2005 at 03:59 AM. Reason: resolved
    The Bloke
    www.blokeinthekitchen.com
    making cooking cool for blokes

  2. #2
    Fanatic Member kaihirst's Avatar
    Join Date
    Jul 2005
    Location
    The Resaurant At the End of The Universe
    Posts
    633

    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
    Last edited by kaihirst; Oct 26th, 2005 at 07:29 AM.
    As the information I give is useful in its nature, consider using the RATE POST feature located on the bottom left of this post please..

    A few things that make a good Developer a Great One.
    Methodical and a thorough approach to research and design inevitably leads to success.
    Forward thinking is the key to Flow of control.
    Never test in the design environment, always test in real time, you get the REAL results.
    CBSE & OOSE are the same animal, they just require different techniques, and thinking.
    SEO is a globe of objectives, SE rankings is an end to a means for these objectives, not part of them.
    The key to good design is explicit attention to both detail and response.
    Think Freely out of the "Box" you're in..... You will soar to better heights.

    Kai Hirst - MSCE, MCDBA, MCSD, MCP, MCAP, MSCT


  3. #3

    Thread Starter
    Hyperactive Member thebloke's Avatar
    Join Date
    May 2003
    Posts
    358

    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'
    The Bloke
    www.blokeinthekitchen.com
    making cooking cool for blokes

  4. #4
    Addicted Member Peter1's Avatar
    Join Date
    Aug 2002
    Posts
    166

    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()

  5. #5
    Fanatic Member kaihirst's Avatar
    Join Date
    Jul 2005
    Location
    The Resaurant At the End of The Universe
    Posts
    633

    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
    As the information I give is useful in its nature, consider using the RATE POST feature located on the bottom left of this post please..

    A few things that make a good Developer a Great One.
    Methodical and a thorough approach to research and design inevitably leads to success.
    Forward thinking is the key to Flow of control.
    Never test in the design environment, always test in real time, you get the REAL results.
    CBSE & OOSE are the same animal, they just require different techniques, and thinking.
    SEO is a globe of objectives, SE rankings is an end to a means for these objectives, not part of them.
    The key to good design is explicit attention to both detail and response.
    Think Freely out of the "Box" you're in..... You will soar to better heights.

    Kai Hirst - MSCE, MCDBA, MCSD, MCP, MCAP, MSCT


  6. #6

    Thread Starter
    Hyperactive Member thebloke's Avatar
    Join Date
    May 2003
    Posts
    358

    Thumbs up 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
    The Bloke
    www.blokeinthekitchen.com
    making cooking cool for blokes

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width