p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Professional (http://p2p.wrox.com/forumdisplay.php?f=215)
-   -   Urgent - Send mail with plain view and html view (http://p2p.wrox.com/showthread.php?t=71621)

ashish.dadhwal November 27th, 2008 01:49 AM

Urgent - Send mail with plain view and html view
 
Hi,

I need to send a mail in both formats together (plain text + HTML) so that if on any email client(like Outlook, Thunderbird etc) HTML view is disabled, the plain text should be displayed.

Things that are already tried:
While sending the mail I am creating an "AlternateView" for both plain Text and HTML and assigning it to the Message object. Below shown is the code:

//////////////////////////////////////////////////////////////////
SmtpClient smtpClient = new SmtpClient();
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(fromAddress, toAddress);

message.Subject = subject;

// Add the alternate body to the message (Plain text message) . The parameter "body" contains the plain text.
AlternateView plainView = AlternateView.CreateAlternateViewFromString(body);
plainView.ContentType = new ContentType("text/plain");

// Add the alternate body to the message (HTML message) . The parameter "htmlBody" contains the HTML text
AlternateView htmlView = AlternateView.CreateAlternateViewFromString(htmlBo dy);
htmlView.ContentType = new ContentType("text/html");

message.AlternateViews.Add(plainView);
message.AlternateViews.Add(htmlView);

smtpClient.Send(message);

//////////////////////////////////////////////////////////////////

The mail was sent successfully but the problem here is with testing Plain View. In Outlook I selected the option to "Read all Std. Mails in Plain Text" but contents of the mail is HTML conversion into normal text but not the Plain Text view. In mail header the content type shows : multipart/alternative.
This functionality was even tested on Thunderbird on Windows as well as on Apple mail client but is not working as expected.


Appreciate any help to display Plain + HTML view on email client.






All times are GMT -4. The time now is 12:01 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.