Problem with System.Web.Mail.MailMessage and HTML mail

Discussion in 'ASP .Net' started by =?Utf-8?B?TWlja2VCb3k=?=, Jun 15, 2005.

  1. Hi all!

    I'm trying to send a HTML mail using the MailMessage class. Sending the
    message works fine, but there is something funny with the received message. I
    use the code below to generate and send a sample message. When I recieve it
    and open it in Outlook 2003 the style for my table cell is not applied. This
    is because the dot (.) before the class in the style tag has been removed!!
    If I insert another dot before class definition in the style tag, one is
    removed and the result is displayed correctly. If I insert a space before the
    dot, the space remains and everything is fine. Why is this happening and
    where can I learn more about this? Where should I look for errors: sending or
    receiving?

    Best Regards

    Mikael

    Dim strHTMLPage As String = ""

    'Head of HTML file
    strHTMLPage = "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0
    Transitional//EN"">" & vbCrLf
    strHTMLPage += "<HTML>" & vbCrLf
    strHTMLPage += "<HEAD>" & vbCrLf

    'style start
    strHTMLPage += "<style type=""text/css"">" & vbCrLf
    strHTMLPage += "<!--" & vbCrLf

    'style class
    strHTMLPage += ".DemoClass { height: 18px; font-size: 10px;
    font-weight: bold; font-family: verdana; background-color: #adbdce; }" &
    vbCrLf

    'end of style
    strHTMLPage += "-->" & vbCrLf
    strHTMLPage += "</style>" & vbCrLf

    'end of head
    strHTMLPage += "</HEAD>" & vbCrLf
    strHTMLPage += "<BODY>" & vbCrLf

    'body content
    strHTMLPage += "<TABLE width=""250"" height=""25"">" & vbCrLf
    strHTMLPage += "<TR>" & vbCrLf
    strHTMLPage += "<TD class=DemoClass>" & vbCrLf
    strHTMLPage += "Just testing" & vbCrLf
    strHTMLPage += "</TD>" & vbCrLf
    strHTMLPage += "</TR>" & vbCrLf
    strHTMLPage += "</TABLE>" & vbCrLf

    'end of body
    strHTMLPage += "</BODY>" & vbCrLf
    strHTMLPage += "</HTML>" & vbCrLf

    Dim Msg As New MailMessage
    Msg.To = strTo
    Msg.From = strFrom
    Msg.Subject = "Test Message"
    Msg.BodyFormat = MailFormat.Html
    Msg.Body = strHTMLPage

    SmtpMail.Send(Msg)
    --
    Micke
     
    =?Utf-8?B?TWlja2VCb3k=?=, Jun 15, 2005
    #1
    1. Advertising

  2. First I thought that this was an encoding problem and now I have tried every
    encoding available with no luck.

    Does anyone have a clue?

    --
    Micke

    "MickeBoy" wrote:

    > Hi all!
    >
    > I'm trying to send a HTML mail using the MailMessage class. Sending the
    > message works fine, but there is something funny with the received message. I
    > use the code below to generate and send a sample message. When I recieve it
    > and open it in Outlook 2003 the style for my table cell is not applied. This
    > is because the dot (.) before the class in the style tag has been removed!!
    > If I insert another dot before class definition in the style tag, one is
    > removed and the result is displayed correctly. If I insert a space before the
    > dot, the space remains and everything is fine. Why is this happening and
    > where can I learn more about this? Where should I look for errors: sending or
    > receiving?
    >
    > Best Regards
    >
    > Mikael
    >
    > Dim strHTMLPage As String = ""
    >
    > 'Head of HTML file
    > strHTMLPage = "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0
    > Transitional//EN"">" & vbCrLf
    > strHTMLPage += "<HTML>" & vbCrLf
    > strHTMLPage += "<HEAD>" & vbCrLf
    >
    > 'style start
    > strHTMLPage += "<style type=""text/css"">" & vbCrLf
    > strHTMLPage += "<!--" & vbCrLf
    >
    > 'style class
    > strHTMLPage += ".DemoClass { height: 18px; font-size: 10px;
    > font-weight: bold; font-family: verdana; background-color: #adbdce; }" &
    > vbCrLf
    >
    > 'end of style
    > strHTMLPage += "-->" & vbCrLf
    > strHTMLPage += "</style>" & vbCrLf
    >
    > 'end of head
    > strHTMLPage += "</HEAD>" & vbCrLf
    > strHTMLPage += "<BODY>" & vbCrLf
    >
    > 'body content
    > strHTMLPage += "<TABLE width=""250"" height=""25"">" & vbCrLf
    > strHTMLPage += "<TR>" & vbCrLf
    > strHTMLPage += "<TD class=DemoClass>" & vbCrLf
    > strHTMLPage += "Just testing" & vbCrLf
    > strHTMLPage += "</TD>" & vbCrLf
    > strHTMLPage += "</TR>" & vbCrLf
    > strHTMLPage += "</TABLE>" & vbCrLf
    >
    > 'end of body
    > strHTMLPage += "</BODY>" & vbCrLf
    > strHTMLPage += "</HTML>" & vbCrLf
    >
    > Dim Msg As New MailMessage
    > Msg.To = strTo
    > Msg.From = strFrom
    > Msg.Subject = "Test Message"
    > Msg.BodyFormat = MailFormat.Html
    > Msg.Body = strHTMLPage
    >
    > SmtpMail.Send(Msg)
    > --
    > Micke
     
    =?Utf-8?B?TWlja2VCb3k=?=, Jun 21, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bertus Dam
    Replies:
    5
    Views:
    885
    Bertus Dam
    Aug 29, 2003
  2. stuart
    Replies:
    1
    Views:
    2,592
    Jacky Kwok
    Nov 10, 2003
  3. martin
    Replies:
    5
    Views:
    2,123
    Hans Kesting
    Dec 19, 2003
  4. techie
    Replies:
    3
    Views:
    2,625
    Phil Wilson
    May 12, 2004
  5. Raj
    Replies:
    0
    Views:
    399
Loading...

Share This Page