tags:

views:

77

answers:

4

using this code to send email

var message = new MailMessage("[email protected]", "[email protected]");
message.Subject = "Testing";
message.IsBodyHtml = true;
message.Body = "<html><body>IMAGINE A LOT OF HTML CODING HERE</body></html>";

The problem is...I just copied the HTML that I want to send as email and now I have to make the whole HTML code in ONE single!! otherwise it is saying ";" missing!! I mean I can't now keep on removing spaces and put it ALL in one line! Its too much HTML code that I need to send..what do I do ? :/

[EDIT] another ques : Is there a linit to this message.Body ??? like limit to how much HTML can be inserted in this ??

+5  A: 

You can use the @ character:

message.Body = @"
    <html>
        <body>
            IMAGINE A LOT OF HTML CODING HERE
        </body>
    </html>";

This works OK if you have a small HTML markup / want a quick-and-dirty solution. For production code, I recommend you use what Jon Skeet suggests, keeping a separate HTML file.

Dan Dumitru
Reference: http://msdn.microsoft.com/en-us/library/aa691090(VS.71).aspx
T.J. Crowder
+1  A: 

Put the text onto multiple lines?

message.Body = "<html><body>IMAGINE A LOT OF "+
                " HTML CODING HERE</body></html>";
Brissles
+8  A: 

Dan has given one option - verbatim string literals - but I'd like to suggest that you move the data into a separate HTML file. Embed it as a resource within your assembly, and then you can load it in at execution time.

That way you'll get HTML syntax highlighting, you won't clutter up your code with a lot of data, and you can edit it really easily at any time, without having to worry about things like double quotes (which would need to be doubled within a verbatim string literal, or escaped with a backslash in a regular string literal).

The downside is that it becomes harder to put user data within the HTML - for that, you might want to consider using a templating system; either simply handwritten (html = html.Replace("$user", name)) or one of the various templating libraries available. Be careful to use HTML escaping where appropriate, of course.

Jon Skeet
ok will try to do that..thnx
Serenity
+1  A: 

Answer to your second question :

"The Body property can contain any object whose size does not exceed 4 MB"

From http://msdn.microsoft.com/en-us/library/system.messaging.message.body.aspx

Wilko de Zeeuw
kk..thnx for the link
Serenity