We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

New attachments are not added if PreserveTnefAttachments is used

Hi,

I found other issue connected with the use of PreserveTnefAttachments flag. If I add new attachment(s) and save message with PreserveTnefAttachments flag, then saved message does not show them (perhaps they were not even saved to the message).

Here is code to replicate:

private static void Test05()

{

MailMessage m = MailMessage.Load("ExchangeMessage.eml");

m.Attachments.Add(new Attachment(File.OpenRead(@"Untitled.png"),

"image-octet-stream.msg", "application/octet-stream"));

m.Save("ExchangeMessage-with-image.eml",

FileCompatibilityMode.PreserveTnefAttachments);

}

<span style=“font-size:11.0pt;line-height:115%;font-family:“Calibri”,“sans-serif”;
mso-ascii-theme-font:minor-latin;mso-fareast-font-family:Calibri;mso-fareast-theme-font:
minor-latin;mso-hansi-theme-font:minor-latin;mso-bidi-font-family:“Times New Roman”;
mso-bidi-theme-font:minor-bidi;mso-ansi-language:EN-US;mso-fareast-language:
EN-US;mso-bidi-language:AR-SA”>Please use files from the project I attached
earlier (in ticket <a href="https://forum.aspose.com/t/35208). I use Aspose.Email v4.0.0

<o:p></o:p>

Best regards,
Alex Shloma

Hi Alex,


Thank you for contacting Aspose support team again.

We are analyzing the issue and request you to spare us little time to complete our investigation. We will will write back here to share our findings as soon as analysis is done here.

Thank you for your patience in this regard.

Hi Alex,


I have tested the scenario and here is a sample code which adds image as attachment to the message and saves it as TNEF attachment. Could you please give it a try and let us know your feedback?

string dir = @“D:\Aspose\ExchangeMessage\ExchangeMessage”;
using (FileStream fileStream = File.OpenRead(dir + “Untitled.png”))
{
MemoryStream memStream = new MemoryStream();
memStream.SetLength(fileStream.Length);
fileStream.Read(memStream.GetBuffer(), 0, (int)fileStream.Length);

MailMessage eml = MailMessage.Load(dir + “ExchangeMessage.eml”);
eml.AddAttachment(new Attachment(memStream, “winmail.dat”, “application/ms-tnef”));
eml.Save(dir + @“Output.eml”, MailMessageSaveType.EmlFormat);
}

Hi,


I attached sample message for you to try my code on your side. This is message from exchange server. The key point here is – entire original main message is EML message with one MIME root part (application/ms-tnef; name="winmail.dat") and this means that TNEF part contains main message info, message body (html) and all attachments (embedded messages, regular and inline attachments). If you try my code you will see, that saves message does not contain newly added attachment. Moreover, saved message has smaller size (41 305 > 32 056), that makes me think, that there is some loss of data.


Your code snippet creates “Output.eml” which is also EML message, but it is “multipart/mixed” – it contains several MIME parts:

  • text/html; charset="UTF-8" with message body in html format;
  • application/octet-stream; name="image001.png" with signature image;
  • application/octet-stream; name="Message with signature.msg" for embedded message
  • and one application/ms-tnef; name="winmail.dat" which contains only one image. winmail.dat” attachment is just base64 encoded image.

Please try my code with attached EML message.


Thanks,

<span style=“font-size:11.0pt;line-height:115%;font-family:“Calibri”,“sans-serif”;
mso-ascii-theme-font:minor-latin;mso-fareast-font-family:Calibri;mso-fareast-theme-font:
minor-latin;mso-hansi-theme-font:minor-latin;mso-bidi-font-family:“Times New Roman”;
mso-bidi-theme-font:minor-bidi;mso-ansi-language:EN-US;mso-fareast-language:
EN-US;mso-bidi-language:AR-SA”>Alex Shloma

Hi Alex,


Thank you for providing more detail.

I have tested the scenario and found that new attachment is not added in the existing TNEF part. This issue is logged in our issue tracking system under id: NETWORKNET-34347 for development team. You will be notified automatically once the feedback is received as this ticket is linked with this forum thread.

Please feel free to to write us back if you have any other query related to Aspose.Email.

Could you please move this ticket to Priority Support forum?

Thanks in advance,

Alex Shloma

Hi Alex,


Could you please try the following code sample to add the attachment and let us know your feedback?

Sample Code:

MailMessage msg = MailMessage.Load(“MainMessage.eml”);<o:p></o:p>

MailMessage embeddedMessage = null;

using (MemoryStream msTnef = new MemoryStream())

{

msg.Attachments[0].Save(msTnef);

embeddedMessage = MailMessage.Load(msTnef);

}

embeddedMessage.Attachments.Add(new Attachment(File.OpenRead("s.png"), "s.png", "image/png"));

embeddedMessage.Save(msg.Attachments[0].ContentStream, MessageFormat.Msg);

msg.Save("test.eml", FileCompatibilityMode.PreserveTnefAttachments);

Hi,

I tried your code snippet. It do adds image to the embedded message, but in my initial post I stated, that cannot add attachments to the main message (“MainMessage.eml” in your code snippet) if PreserveTnefAttachments flag is used.


I added one line to your code snippet to demonstrate the issue.


MailMessage msg = MailMessage.Load("ExchangeMessage.eml");

MailMessage embeddedMessage = null;

using (MemoryStream msTnef = new MemoryStream())

{

msg.Attachments[0].Save(msTnef);

embeddedMessage = MailMessage.Load(msTnef);

}

embeddedMessage.Attachments.Add(new Attachment( File.OpenRead("Untitled.png"), "Untitled.png", "image/png"));

embeddedMessage.Save(msg.Attachments[0].ContentStream, MessageFormat.Msg);

msg.Attachments.Add(new Attachment(File.OpenRead("Untitled.png"), "Untitled.png", "image/png"));

msg.Save("ExchangeMessage_007.eml", FileCompatibilityMode.PreserveTnefAttachments);


Please postpone moving this ticket to Priority Support forum. Will consider the necessity and let you know if it is still needed.

Hi Alex,

We are sorry for a delayed response. Please spare us a little time to investigate this issue in detail at our end. We’ll share our findings here with you soon.

Hi Alex,


We have further investigated this issue and found that adding new attachment is not supported in this case. An enhancement ticket with id: NETWORKNET-34370 has been logged in our issue tracking system for implementation of this feature. We’ll keep you updated about the status of this issue via this thread.

The issues you have found earlier (filed as NETWORKNET-34370) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.