1

Why when i send html email it looks like:

enter image description here

but initial page is:

enter image description here

Here is code:

MailMessage message = new MailMessage();
                message.IsBodyHtml = true;
                message.Subject = subject;
                message.Body = body;

                foreach (MailAddress recipient in recipients)
                {
                    message.To.Add(recipient);
                }
                if (message.To.Count > 0)
                {
                    SmtpClient smtp = new SmtpClient();
                    smtp.Send(message);
                    return true;
                }

Html file contains css in head. http://pastebin.com/r5V6X4Ld

2
  • What is the content of body? Commented May 18, 2011 at 9:55
  • @mahesh: I can... Maybe blocked by your proxy? Commented May 18, 2011 at 9:56

2 Answers 2

1

I assume that the body variable only contains the HTML code, but not the CSS or the images, because both are separate files.
Basically, you need to attach the images to the mail and change the HTML code of the body to point to the correct location. See here for more info and sample code.

This might also be helpful: http://www.alistapart.com/articles/cssemail/

Problem:

Some clients rendered my email with no style whatsoever. I first attributed this to the stripping of styles, but I then discovered that the styles were clearly visible in the source code. I subsequently spent a good deal of time attempting to uncover the culprit, testing countless versions of the email. Alas, the problem was right under my nose: the styles weren’t being stripped — the dots (.) preceding their names were. Therefore, “.Feature {}” became “Feature {}”, resulting in a meaningless style definition.

Solution:

I used class selectors, which ensured that each style would begin with a letter instead of a dot. So “.Feature {}” would become “td.Feature {}” or “div.Feature {}” (depending on the application). A somewhat mundane fix, but effective and (again) compliant.

Sign up to request clarification or add additional context in comments.

4 Comments

NO. Html file contain css style.
@Daniel Hilgarth Thanks but images is not a problem. Problem is that page looks like css doesnt loaded.
Please post the content of body.
@Neir0: Thanks. Please see update to my answer. The provided link might help you.
0

You have to refer your image with full path ie www.yourdomain/imagename.jpg etc and also have to give the class as inline styles

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.