Brec
Brec

Reputation: 97

asp.net how to send email with html tags as text

I want to send email that has html tags as text

This is what I send

string sctipt = "<script src = http://whatever.com  type = text/javascript></script>";
message.Body = string.Format("script:{0}", script); 

the mail is send but without the string "<script src = http://whatever.com type = text/javascript></script>" because its coming as html tag and I need it to be send as text.

Any idae anyone?
Thanks in advance

Upvotes: 1

Views: 70

Answers (2)

VDWWD
VDWWD

Reputation: 35564

Use HtmlEncode

string script = "<script src=\"http://whatever.com\" type=\"text/javascript\"></script>";
message.Body = Server.HtmlEncode(script);

or

message.Body = System.Net.WebUtility.HtmlEncode(script);

Upvotes: 0

Ephellon Grey
Ephellon Grey

Reputation: 420

Three notes:

  • Why are you trying to send scripts in an email? They'll be blocked by default.
  • string script instead of string sctipt
  • '&lt;script src="http://whatever.com" type="text/javascript"&gt;&lt;/script&gt;'

Upvotes: 1

Related Questions