sumedha sumedha - 7 months ago 9
HTML Question

Applying style to <a href> tag placed inside C# code

I am using html code inside a .cs file to design a template for sending emails. I have added style tag to the

<a href>
tag, but it does not take effect when the email is actually sent.
Here is the code:

public static void Email()
{
StringBuilder sb= new StringBuilder();
sb.Append("<a href='#' style='font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;color:#fff;text-decoration:none;line-height:2em;font-weight:bold;text-align:center;display:inline-block;border-radius:5px;text-transform:capitalize;background-color:#208ed5;margin:0;border-color:#208ed5;border-style:solid;border-width:10px 20px' target='_blank'>");
sb.Append("link</a>");
}

Answer

Escape the quotes with backslash:

style=\"font-family:\'Helvetica Neue\',Helvetica,Arial,sans-serif;font-size:14px;color:#fff;text-decoration:none;line-height:2em;font-weight:bold;text-align:center;display:inline-block;border-radius:5px;text-transform:capitalize;background-color:#208ed5;margin:0;border-color:#208ed5;border-style:solid;border-width:10px 20px\"