I am using this code to send email
var message = new MailMessage("abc@somedomain.com", "administrator@anotherdomain.com");
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 line! Otherwise it is saying “;” missing! I mean, now I can’t keep on removing spaces and put it ALL in one line! It’s too much HTML code that I need to send. What do I do ? :/
[EDIT]
Another question: Is there a limit to this message.Body? Like a limit to how much HTML can be inserted in this?
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.