Broken appointment with attachments

Hi,

I faced with issue while processing appointment message. In case of external recipient Exchange sends
message (through SMTP) with two alternative views: (1) text/plain;; (2) application/ms-tnef;
name=“winmail.dat” (“original_message.eml” attached). The problem is when I open message, replace content of attachment
(DOCX-file) using following code:

MailMessage main = MailMessage.Load(@“original_message.eml”);
main.Attachments[0].ContentStream = new MemoryStream(File.ReadAllBytes("file.docx"));
SendMethod(main);

message comes to recipient (please see attached image):

  1. in plain text
  2. stripped of calendar appointment

The same result you can get saving main message to eml-file.

main.Save("saved_Has_no_appointment.eml"); // also attached

The reason of such a behavior (stripping of calendar appointment) is that all information about appointment is contained in TNEF properties of “winmail.dat” and is lost during creating new MailMessage instance.

I tried following code:

MailMessage main = MailMessage.Load(@"original_message.eml", FileCompatibilityMode.PreserveTnefAttachments);

And recipient will receive message correctly. But it work for me only if message has no attachments. Because if I use ‘PreserveTnefAttachments’ then Attachments collection of ‘main’ message does not contain docx-file, only “winmail.dat” (but I need to have access to docx file to replace content of this attachment).

My question is how I can manipulate attachments without breaking meeting appointments?

Best regards,
Alex Shloma

Hi Alex,


Thank you for using Aspose.Email and please accept our apology for a delayed response.

I was able to observe the issue as you have mentioned in your posting. The appointment is lost when the message is saved after loading. I have forwarded these details to our development team for further investigation by logging it as: NETWORKNET-33481. We will update you here once we have any information for the resolution of this issue. We are sorry for the inconvenience you have faced.

Hi Kashif,


Thank you! This is urgent issue for me, so I’m looking forward to get this issue fixed.

Best regards,
Alex Shloma

Hi Alex,

Please try the following lines of code and let us know your feedback.

MailMessage main = MailMessage.Load(@"original_message.eml");

main.Attachments[0].ContentStream = new MemoryStream(File.ReadAllBytes("leoWork.docx"));

main.Save("saved_Has_no_appointment.eml", FileCompatibilityMode.PreserveTnefAttachments);

Hi Kashif.

Thanks for the work you do. Your sample code works fine.

But to use it in my scenario I need to add two additional operation (save+load) which is a hit on application performance, because require additional manipulations with hard drive.

MailMessage main = MailMessage.Load(@"test_messge.eml");

main.Attachments[0].ContentStream = new MemoryStream(File.ReadAllBytes(@"test.docx"));

//if I send message here, then message will be received without appointment
main.Save(@"saved_with_new_attachment_and_winmail.data.eml", FileCompatibilityMode.PreserveTnefAttachments);

main = MailMessage.Load(@"saved_with_new_attachment_and_winmail.data.eml", FileCompatibilityMode.PreserveTnefAttachments);

SmtpClient sc = new SmtpClient("host", 2525, "login", "password");

sc.Send(main);

Is there any way to achieve the same result as in the code above without additional save-load operations?

Thanks,

Alex

One more question,


If messages does not have tnef, does this flag FileCompatibilityMode.PreserveTnefAttachments affect on anything? I mean will it be safe to always use PreserveTnefAttachments flag?

Thanks,
Alex

Hi Alex,

Thanks for contacting Aspose.Email support team.

Following code avoids the repetitive access to the harddisk and performs save and load operation in the memory only.

Please give a try to this code and let us know your feedback.

MailMessage main = MailMessage.Load(“test_messge.eml”);
main.Attachments[0].ContentStream = new MemoryStream(File.ReadAllBytes(“test.docx”));

//if I send message here, then message will be received without appointment
MemoryStream memStr = new MemoryStream();

[//main.Save](https://main.save/)(“saved_with_new_attachment_and_winmail.data.eml”, FileCompatibilityMode.PreserveTnefAttachments);
main.Save(memStr, FileCompatibilityMode.PreserveTnefAttachments);

//main = MailMessage.Load(“saved_with_new_attachment_and_winmail.data.eml”, FileCompatibilityMode.PreserveTnefAttachments);
main = MailMessage.Load(memStr, FileCompatibilityMode.PreserveTnefAttachments);

SmtpClient sc = new SmtpClient(“host”, 2525, “login”, “password”);
sc.Send(main);
Hi Alex,

LiteraCorp:
If messages does not have tnef, does this flag FileCompatibilityMode.PreserveTnefAttachments affect on anything? I mean will it be safe to always use PreserveTnefAttachments flag?

I have tried different types of messages with and without attachments and found that this option is effective only when there is "winmail.dat" present in the mail, otherwise it has no effect, so you may use this option.




kashif.iqbal:
Hi Alex,

LiteraCorp:
If messages does not have tnef, does this flag FileCompatibilityMode.PreserveTnefAttachments affect on anything? I mean will it be safe to always use PreserveTnefAttachments flag?

I have tried different types of messages with and without attachments and found that this option is effective only when there is "winmail.dat" present in the mail, otherwise it has no effect, so you may use this option.





Thank you! Very helpful information.

Best regards,
Alex Shloma
Hi Kashif,

Thank you, your code with MemoryStream works as expected. But anyway, it's extra actions - to save into memory stream and then read this stream. It takes time, and if email will have big attachments (around few Mb) - delay will be noticeable.

I see for now you do not have ability to send email with tnef without extra actions. Are you going to implement such functionality in future?

Thanks,
Alex Shloma

Hi Alex,


Thank you for the feedback.

While investigating this issue further, I have found that sending this message is often posing difficulties. I was able to send the message a couple of times, but then it couldn’t be sent. Please share with us your experience in this regard. I am sending email to my Exchange account from my Gmail using Aspose.Email SmptClient. Please share your feedback with us so that we can investigate this issue further.

Hi Kashif,


I’ve tried to send email several times and all messages were sent fine. Could you please detailed describe what did you do, and what difficulties you faced.

P.S. I guess you was blocked by some Gmail or Exchange security thing.

Thanks,
Alex Shloma

Hi Alex,


Thank you for the feedback.

We simply tried to send this file using the Aspose SmtpClient with Gmail as Smtp server and was destined for an account on an Exchange server. It may be that there are some security settings that might be blocking it.

Anyways, can you please provide us details on how are you sending the email and, if possible, provide us the sample code used for this purpose. Ideally, it should be able to send the email without any extra actions. We will look into this and report it to our development team for further investigation.

Hi Kashif,

In my scenario Exchange server relay all outbound messages (with ‘winmail.dat’) to intermediate server which analyze every message, replace content of attachments (if needed) and forward message to “smart host” which sends message to internet.

Complete sample:

MailMessage main = MailMessage.Load("path to saved .eml file");

//saving and processing attachments

// ......

//replaceing attachments
main.Attachments[0].ContentStream = new MemoryStream(File.ReadAllBytes(@"path to processed attachment"));

MemoryStream ms = new MemoryStream();

//extra actions: 'save' and 'Load'. Message comes stripped of appointment without them.
main.Save(ms, FileCompatibilityMode.PreserveTnefAttachments);

main = MailMessage.Load(ms, FileCompatibilityMode.PreserveTnefAttachments);

//sending message
SmtpClient sc = new SmtpClient("host", 25, "login", "password");

sc.Send(main);

Thanks,

Alex Shloma

Hi Alex,


Thank you for the feedback.

We will analyze this issue further and if this seems to be a bug to us, we will forward it to our development team for further investigation. We will also share our findings with you soon. Thank you for your patience.

Thanks a lot for your assistance!


Hi Alex,


Thank you for being patient during our investigation.

I was able to reproduce the issue as you mentioned in your earlier posting. Appointments are stripped off when these are sent using Smtp client. I have tried different methods and obtained the same result. To further investigate this issue, I have logged these details in our issue tracking system under issue ID: NETWORKNET-33503. Our development team will look into it and once we have any information in this regard, we will update you here.

Thank you for support!


Many thanks,
Alex Shloma

Hi Alex,


You are welcome and please feel free to write us if you have any further queries. We will be more than happy to assist you as much as possible.





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


This message was posted using Notification2Forum from Downloads module by aspose.notifier.