473,324 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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(Msg)
--
Micke
Nov 19 '05 #1
1 1953

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

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Trond A. S. Andersen | last post by:
Hi, all! I'm trying to use the System.Web.Mail. "package" combinded with System.Web.Mail.SmtpMail in order to send MS Excel spreadsheets attached to mail messages. However, sending one single...
3
by: Phil Mc | last post by:
Hi has anyone come accross the problem.... with referance to System.Web.Mail.MailMessage and System.Web.Mail.SmtpMail THIS WORKS FINE mail=new MailMessage(); mail.From =...
5
by: martin | last post by:
Hi, I have created a class that is totally seperate from my web application. However this class is used extensivly by the web application for stuff like data access. I wish to add a function to...
5
by: ElanKathir | last post by:
Hi ! I wrote one code for Send the E-mail, But that code have some problem , So please help me Here i paste my code and Error: Error: Server Error in '/Elan_Sample' Application. ...
3
by: pmud | last post by:
Hi, I have ab ASP.Net Application in which I need to send e-mail on button click. Even though my C# code for that is correct.I am getting the following error:: I think the following error can be...
2
by: ChrisA | last post by:
I'm sending email from my ASP.NET 1.1 app, and it works fine providing the BodyFormat of the System.Web.Mail.MailMessage is set to Text. If I change to Html format, it breaks. Here's the code: ...
2
by: clevrmnkey | last post by:
I've had nothing but trouble from the System.Net.Mail objects, but I finally need to make them work, and I can't for the life of me see what I'm doing wrong. I pared back my mail transaction to...
1
by: erPanita | last post by:
Hello.. I'm using the C# class System.Net.Mail.MailMessagein order to send Emails in HTML Format. The HTML body comes from a Crystal Report converted to HTML Format 40 through the Crystal Class from...
2
by: joseph2000 | last post by:
Hi, I have problem with e-mails which are being send via System.Web.Mail.SmtpMail class but before describing the problem itself first I'd like to show shortly what I'm doing on the server. ...
2
by: =?Utf-8?B?Q2FwdGFpbiBEYXZlIQ==?= | last post by:
I wrote some code to send an email with two alternate views: 1) html 2) plain text All the html enabled email clients accept the html just fine and disregard the plain text version. However,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.