0

I have a problem I want to send a html sting by c# in asp.net mvc when i use readalltoend a html page by streamreader it works good But !!! I need to get a string like this :

<html>
<head>
</head>
<body>
//some html code
</body>
</html>

I get this as a string an try to send it , when it sended it has no style and show like a string not html I've tried with streamwriter to write it to a html file and read it again but it doesn't solve my problem plz help me

tereško
  • 58,060
  • 25
  • 98
  • 150
user2830448
  • 427
  • 1
  • 8
  • 20

2 Answers2

4

When you are using System.Net.Mail and you want to send html as the message, make sure your set :

mail.IsBodyHtml = true

http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.isbodyhtml(v=vs.110).aspx

middelpat
  • 2,555
  • 1
  • 20
  • 29
  • 1
    If possible I'd actually recommend using MIME rather than HTML. Many spam filters don't like emails which don't have a plaintext version included. http://stackoverflow.com/questions/5483799/how-to-send-multi-part-mime-messages-in-c – Liath Feb 05 '14 at 11:52
  • I never ran into this problem, maybe it's because i use a trusted mail server which helps with passing spamfilters. However this is a good suggestion, I will also have a look myself at this link – middelpat Feb 05 '14 at 12:44
  • it's just one of many many factors I've found which may sometimes trip a spam filter. If you're not having trouble I suggest you don't mess with it! http://stackoverflow.com/questions/9504911/sending-email-with-php-and-ensuring-it-doesnt-get-blocked/9505137#9505137 – Liath Feb 05 '14 at 12:46
1

Try

MvcMailMessage.IsBodyHtml = true;
Sameer
  • 2,143
  • 1
  • 16
  • 22