Click here to Skip to main content
15,868,048 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing an Outlook AddIn where content of a mail body will be stored in a control when user clicks on the AddIn button. After that the control should have capability to edit the content. I am using WinForm for this.

I tried using the following Rich Text Editor control for winforms:

https://yarte.codeplex.com/

A Windows Forms based text editor with HTML output

I tried to access the mail body in following way:

C#
Outlook.Application oApp = new Outlook.Application();
Outlook.Explorer oExplorer = oApp.ActiveExplorer();
Outlook.Selection oSelection = oExplorer.Selection;

foreach (object item in oSelection)
{
    Outlook.MailItem oldMailItem = (Outlook.MailItem)item;
    //This is YARTE Control
    htmlEditor1.Html = oldMailItem.HTMLBody;

    //Other Control
    editor1.BodyHtml = oldMailItem.HTMLBody;
}


When I try to edit the content of control(to change font,size,color etc.),it works fine if the mail body contains plain text. but when the mailbody has rich text (colored, different font), the content of the control is not edited properly.

Am I missing something ?

Or is there any other control which will accomplish my requirement ?
Posted
Updated 17-Nov-15 22:11pm
v2
Comments
BillWoodruff 18-Nov-15 4:11am    
The first thing to do is to establish what the format of the incoming text is, and what formats the editor you are using supports. Is it possible that "mailbody" richtext is not standard RTF ?
Digambar Malla 18-Nov-15 5:14am    
Bill, MailBody is in standard HTML format...
BillWoodruff 18-Nov-15 5:23am    
Okay, but does the Control you use to display/edit the Text accept HTML format ? There's also the possibility that Outlook HTML may not be "standard" HTML. The important point is that you research exactly what format you have.
Digambar Malla 18-Nov-15 5:39am    
Bill, MailBody is in RAW HTML format which I think is different from regular HTML...but the 3rd party controls are HTML editor. So,what should I do now ?

What makes you think that HTML and RTF are the same thing? They aren't even close!
And what you are reading from the email message is specifically the HTML - so you need to check what the controls you reference are doing with that.

So ask the people who wrote them.
In the case of the CP article, there is a message area at the bottom which talks direct to the author. Posting here relies on him "dropping by" and realizing that it's for him.
In the other case, then you need to contact the author some other way: we don't even know if he is a member of this site!
 
Share this answer
 
Comments
Digambar Malla 19-Nov-15 0:39am    
Griff, thanks for the valuable suggestion. Also what I am getting from Outlook mailbody is something called olFormatHTML (I think it is same as HTML !!!).May be there is some issue the way the third party control is handling the content from mail body ,because if mail body contains plain text (i.e without any colored,bold,italic text) there is no issue at all. Also in the control if I manually put some colored text, I am able to format it...I am really stuck on this as my lead have no idea. Is there any other control which will accomplish my requirement ?
First, to make sure it's "real raw HTML" with no external dependencies (CSS, JavaScript libraries, etc.), I'd stick it in a file, set the extension to .html, and see if any standard browser will open it and display it as you expect it should appear. If that fails, I'd start studying a sample e-mail message body in that format, and look for any "weirdness" ... however, you may have already done that.

Assuming that doesn't lead you to any insights: I suggest you start by studying the format of Outlook E-mail messages, taking note that:
Quote:
All e-mail applications are not alike, so you need to use a message format that your recipient's application supports. Microsoft Outlook offers the flexibility in message formats that you need for different situations. The message format that you choose determines whether you can add formatted text, such as bold fonts, colored fonts, and bullets, and whether you can add pictures to the message body. However, just because you choose a message format that lets you add these features doesn't mean the recipient will be able to see them. That is because some e-mail applications don't support formatted messages or pictures.
[^]

If you finally end up rather certain the problem is located in some flaw in the Controls you are using: then take OriginalGriff's excellent advice and contact the authors of the Control(s) you use, and report what you found.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900