Hello team,
I encountered a strange issue, i have an email which is Rich text format , and i insert a picture into its body. The attachments (Embedded piciture) cannot be kept when i export this mail from PST to .eml flle. So i want to know how can i keep the RTF embedded picture when i export mail as .eml.
I have tried some parameters, but it does not work.
For example:
-
Aspose.Email.SaveOptions.DefaultEml.PreserveEmbeddedMessageFormat
but, it cannot be set as true. I set it as true, its value still keep as false.
-
mail.ToMailMessage(new MailConversionOptions() { PreserveRtfContent = true});
I try to use this method , then i export the .eml file. Unfortunately,Embedded picture still cannot be kept.
So i would like to get your help, how i can keep the embedded picture in .eml file.
And i have upload the sample pst file.
RTF.zip (1.6 MB)
Best regards,
Hello @Lincolnisme,
Thank you for reporting your case.
Unfortunately, eml format doesn’t support RTF content. We could save it using PreserveRtfContent, but most email clients don’t display it.
There are two solutions to the problem:
Solution 1
Save messages in msg format
Solution 2
Save a message in eml format but TNEF-encoded. A TNEF-encoded message contains a plain text version of the message and a binary attachment that “packages” other various parts of the original message. This binary attachment may include information such as the formatted text version of the message (e.g., font information and colors), OLE objects (e.g., embedded pictures and embedded Microsoft Office documents), special Outlook features (e.g., custom forms, voting buttons, and meeting requests), and regular file attachments that were added to the original message.
// Load the PST file
using (var pst = PersonalStorage.FromFile("RTF.pst"))
{
// Get the Inbox folder
var inbox = pst.RootFolder.GetSubFolder("RTF");
// Iterate through the messages in the Inbox folder
var messages = inbox.GetContents();
foreach (var messageInfo in messages)
{
// Extract the message and save it as an EML file
var message = pst.ExtractMessage(messageInfo);
// Convert the MapiMessage to a MailMessage
var mailConversionOptions = new MailConversionOptions
{
ConvertAsTnef = true
};
var mailMessage = message.ToMailMessage(mailConversionOptions);
mailMessage.Save("out.eml", SaveOptions.DefaultEml);
}
}
After trying either of the solutions suggested, please, spare a minute to give us your feedback.
Hello @margarita.samodurova,
Thanks for your quick response.
But there are still some questions I want to clear up, i still need your great help and very appreciate it.
1.Since you said eml format does not support RTF content, is it a known issue, or there are some limitation?Could you help provide more details about it?
2.Could you help explain what that means “does not support”, are there any specific issue? i want to know more about it.
3.As previous question,i found some parameters about RTF or embedded ,and they are seems to be related to eml,since we does not support it,why are these parameters there,some limitations in API?
Sorry for my 3 questions, i just want to know the root cause and details. Looking forward to your reply. Very appreciate it.
Have a nice weekend.
Best regards,
@Lincolnisme,
I must have expressed the idea inaccurately. Let me correct myself. EML is a file format used to store email messages, and it can include different types of content, such as plain text, HTML, and RTF. When an email message is created with rich formatting options, the RTF content may be preserved when saved as an EML file. Therefore, it’s important to consider the compatibility of email clients when sending EML files with RTF body content, as not all email clients support this formatting option. At least the most common clients do not display it.
That is, to be precise, Aspose.Email can save an RTF content to EML as an AlternateView, but most clients will not display it.
Hello @margarita.samodurova,
Thanks for your response.
Sorry for that i still have questions to clear up.
- as you said, most common clients do not display it , does it include MS-outlook,owa? Could you tell me more details about common clients
- As for “will not display it”, what does it mean? the whole RTF body cannot display ? or some pictures cannot display, or some attachments cannot display ,or some other unexpected behaviors?
Sorry again for my questions, i just want to know more details about it.
Thanks for all your help, very appreciate it.
Best regards,
Hello @Lincolnisme,
Let us answer your questions with the attached example file 1.zip (1.3 KB)
and comments.
When we add RTF content to EML, it is added to the AlternateView collection with content type “text/rtf”.
The MIME type text/rtf is used to denote the presence of Rich Text Format text files.
An alternate view in an EML file is an additional representation of the email content that can be used to provide a different rendering of the email message.
An alternate view is typically used to provide an alternative format of the message that can be displayed in case the recipient’s email client does not support the default format of the message.
For example, an email message may include a HTML version of the message as the primary view, but also include a plain text version as an alternate view. If the recipient’s email client does not support HTML formatting, it will automatically display the plain text version of the message.
MS Outlook does not render RTF content when it opens an EML. Email clients may display RTF as an attachment, or raw text - which indicates RTF is not supported.
To illustrate the above, we attach 1.zip file containing 3 eml files:
- “text_html_rtf.eml” has three AlternateView with the following MIME types: text/plain, text/html и text/rtf. Open it with Outlook. Outlook will render text/html. And will display it in the message body.
- “text_rtf.eml”, has AlternateView with the following MIME types: text/plain и text/rtf. Open it with Outlook. Outlook will render text/plain. And will display it in the message body.
- “rtf.eml” has one AlternateView with text/rtf type. Open it with Outlook. Outlook will not display the message body bbut will add the text/rtf content as an attachment.
Hello @margarita.samodurova,
Thanks for your so detail response,it is very helpful. Very appreciate it.
Now i faced two strange issues, still need your help:
- I use other tool to check .eml 's attachments, i found that the Embedded picture’s attach method was changed to 1(ATTACH_BY_VALUE) from 6(ATTACH_OLE)
- Some attachments’ order was changed unexpectedly.
Could you help me know the reason about above strange issues?
Thanks for all your help.
Best regards,
@Lincolnisme,
Thank you for your feedback.
For further investigation we need a code sample and a file sample from you.
Hello @margarita.samodurova ,
My test code is:
var mail = tempMessage.ToMailMessage(new MailConversionOptions() { PreserveRtfContent = true,PreserveEmbeddedMessageFormat=true });
mail.Save(path, SaveOptions.DefaultEml);
Although i used two parameters,the RTF format still cannot be kept,
I have uploaded my sample data.RTF-Sample.zip (1.6 MB)
The followings are the issue that we are currently aware of.
- Images in rich text are missing.
- The order of attachments in some rich text is changed.
Besides that,is there other known issues related to RFT to eml?Please provide a list of problems that occur when such rich text format mails are converted to EML format mails and displayed in MS Outlook.
For some reasons, we need responses until 4/12. Sorry for any inconvenience. And thanks a million for your help,very appreciate it.
Best regards,
Hello @Lincolnisme,
As we specified above, the problem with RTF in EML is that the eml message body is not displayed by Outlook in RTF.
To solve this problem we suggested saving TNEF eml and provided you with the code sample.
Simply add ConvertAsTnef option to your code:
var mail = tempMessage.ToMailMessage(new MailConversionOptions() { PreserveRtfContent = true, PreserveEmbeddedMessageFormat = true, ConvertAsTnef = true });
After applying this option, please, spare a minute to give us your feedback.
Hello @margarita.samodurova,
Thanks for your quick response, It’s very timely. We test ConvertAsTnef parameter,it looks fine,we plan to use ConvertAsTnef parameter
to deal with RTF mail.
But we worry about that are there some limitations for mail style and attachments behavior if we using ConvertAsTnef parameter.
Could you let me know that are there some limitations or known issues if we export RTF mail as eml with ConvertAsTnef parameter.
Appreciate all your help,thanks soooooooooo…ooo much.
Best regards,
@Lincolnisme,
There may be some limitations when exporting mail as EML with the ConvertAsTnef parameter. Here are some of them:
- Unsupported email clients: The TNEF-encoded messages is supported by Microsoft Outlook and Microsoft Exchange Server perfectly. Some clients and servers may not be able to read or process TNEF-encoded messages.
- Large file size: Because the ConvertAsTnef parameter converts the RTF mail to a TNEF-encoded message, the resulting EML file may be larger than the original message with RTF.
If you use Microsoft apps like Outlook, Exchange server etc. there shouldn’t be any problems.
If you use other services and email clients, consider the use of HTML instead of RTF.
Using HTML format in email messages has several advantages compared to other formats such as plain text or RTF:
- More formatting options: HTML allows for more flexible text formatting and the addition of styles, fonts, images, tables, and links in messages.
- Better support for email clients.
Hello @margarita.samodurova,
Thanks for your detail response, I have no other questions for now.
And thanks again,for your patience and professional knowledge,very appreciate it.
Best regards,
@Lincolnisme,
Thank you for using Aspose products.
Feel free to write to us if you have any additional query/inquiry related to Aspose.Email. We’ll be glad to assist you further.