开发者

System.Net.Mail replacing linefeeds in AlternateView content with spaces

I'm using System.Net.Mail to send out an ics meeting/calendar invitation. The line terminators (0D 0A) in the ics are being replaced with spaces (20 20) in the email that is received. I've googled solutions and tried a few variations of the code below but none of them seem to fix this behavior. Any ideas?

System.Net.Mail.MailMessage m = new System.Net.Mail.MailMessage();
System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType("text/calendar");

ct.Parameters.Add("method", "REQUEST");
ct.Parameters.Add("name",开发者_高级运维 "meeting.ics");

AlternateView avCal = AlternateView.CreateAlternateViewFromString("<<data>>",ct);
avCal.TransferEncoding = System.Net.Mime.TransferEncoding.SevenBit;
m.AlternateViews.Add(avCal);


use

AlternateView htmlView = AlternateView.CreateAlternateViewFromString(body, System.Text.Encoding.UTF8, MediaTypeNames.Text.Html);  


Never mind. My bad... Further debugging revealed that the problem had nothing to do with the encoding or mail portion. Actually looks like the linefeeds are being garbled somewhere between the SQL database and the app. Thanks to everyone who posted advice!


Have you tried using the overload for AlternateView.CreateAlternateViewFromString that accepts an Encoding and MediaType? I use:

AlternateView htmlView = AlternateView.CreateAlternateViewFromString(
            htmlBody, Encoding.UTF8, MediaTypeNames.Text.Html);

and it seems to work ok for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜