1

Good Day.

I want to send an email from my code file in ASP.NET. I want to apply styling to my html...How do I do it?

Here is the html part:

var Message = string.Format("<html><head></head><body><div style=""this does not work!!"">{0}<br/>{1}<br />{2}<br />{3}<br />{4}<br />{5}</body></html>", emaildetail.Name, emaildetail.Surname, emaildetail.CardProvider, emaildetail.CardType, emaildetail.CardNo, emaildetail.SuspendGuid); 

SendEmail("my email address", "Suspended Message", Message, true, null, true, 587);

I tried using double quotes, but it does not work.

How can I do this?

Thank you

4 Answers 4

2

Either use a @ prefix:

@"Some text ""here""";

or use a backslash to escape the quotes:

"Some text \"here\"";
Sign up to request clarification or add additional context in comments.

7 Comments

what does the 'some text' refer to?
whatever your text is.. in thsi case your html
Just stick a @ character in front like this: string.Format(@"<html>...etc and see if that works first
Both of these are the lesser way, IMO; this scenario is perfect for single quotes. the prefix and escaping just make the string more convoluted.
@GrantThomas I see this as a limitation in C# itself. This kind of task would be a lot nicer if C# supported string interpolation like Nemerle or Ruby
|
1

Generally in such circumstances it's much less work and more pretty (as much as that can be) to use single quotes within the double quotes of a literal string; of course you can escape the doubles with a backslash, or a prefixed @, but there's very little point, and more typing or confusion:

<html><head></head><body><div style='this will work!!'

However, another crux of your problem might exist even so, as clients may render styles at discretion.

2 Comments

OH so just single quotes will work just as good? So using single quotes won't make the styling be ignored in any way?
Nope, in fact, by the standards most clients go by, unquoted HTML probably still works in most of them. Single quotes will be fine, if a client is going to ignore a style property it's going to do it regardless.
1
var Message = string.Format(@"<html><head></head><body><div style=""this does not work!!"">{0}<br/>{1}<br />{2}<br />{3}<br />{4}<br />{5}</body></html>", emaildetail.Name, emaildetail.Surname, emaildetail.CardProvider, emaildetail.CardType, emaildetail.CardNo, emaildetail.SuspendGuid);

You need to escape your string using the @.

See this post

Escape Double Quote

Comments

-1

use \ as an escape character before your quotes...

var Message = string.Format("<html><head></head><body><div style=\"\">") 

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.