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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MickeBoy

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

    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(M sg)
    --
    Micke
  • MickeBoy

    #2
    RE: Problem with System.Web.Mail .MailMessage and HTML mail


    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:
    [color=blue]
    > 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(M sg)
    > --
    > Micke[/color]

    Comment

    Working...