0

Good Day.

I am creating an html email in ASP.NET. Now the problem is when I want to add anything to my body except the html and body tags. When I want to add styles, the code file gives me errors, and many of them...

I want to add this

<!DOCTYPE html>
<html>
<head>
        <meta charset="utf-8" />
        <title>Enquiry</title>
    </head>
    <body>
    <div style="margin: 0 auto; text-align: center; background: #3C3B3D; padding: 10px;">
        <h4 style="color: #F3911F">Website Enquiry</h4>
    </div>
    <table style="text-align: center; margin: 0 auto;">
        <tr>
            <td>name: </td>
            <td>{0}</td>
        </tr>
    </table>
    </body>
</html>

Inside this

var html = string.Format("THE HTML HERE", TextBoxName.Text)

Visual studio basically underlines everything (all the html above) when I add it to the string...

How do I format/style my email body in ASP?.

Thank you

2
  • What does your HTML email have to do with TextBoxName.Text? Commented Mar 6, 2013 at 16:35
  • Use stringbuilder to construct the body in html format and send mail. Please ensure to change the mail body format property to html in code. (I.e.,) obj.format = mailformat.html; Commented Mar 6, 2013 at 17:00

2 Answers 2

1

You have to escape all quote characters. There are two options:

// for single line texts use \
var x = "abcd\"efg\"hij";

// for multiple lines use @ and double quotes
var x = @"abcd
""efg""
hij";

When using String.Format you also have to escape any {} characters that might appear (for example, in CSS or JavaScript blocks, using double {{}}

var x = string.Format("This is the value: {0} and this is just the brackets {{asd}}", 1);
Sign up to request clarification or add additional context in comments.

Comments

0

You can use StringBulider.Append()

A simple mail sending code is here

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.