Create Tnef mail

Hello,



How can I create a tnef with winmail.dat?



I tried something that I had seen in the forum:



// Create a new intance of MailMessage



MailMessage eml = new MailMessage("test@test.com", "test@test.com");



// Add the TNEF attachment



eml.AddAttachment(new Attachment(ms, “winmail.dat”, “application/ms-tnef”));



// Save the message in EML format



eml.Save(“TnefEmail.eml”, MailMessageSaveType.EmlFormat);





but when I open the eml file I see the winmail.dat as attachment (while it has to be hidden…)



Please your help,



Thanks,



Roi

Hi Roi,

Thank you for writing to Aspose support team.

Please use the following code to achieve your desired results which is the proper way of creating a TNEF message file.

Sample Code:

// Load the MapiMessage and save it in TNEF format
MapiMessage msg = new MapiMessage();
msg.Attachments.Add("desert.jpg", File.ReadAllBytes("Desert.jpg"));
MemoryStream ms = new MemoryStream();
msg.SaveAsTnef(ms);

// Create tnef eml
MailMessage eml = new MailMessage("test@test.com", "test@test.com");
eml.AddAttachment(new Attachment(ms, "winmail.dat", "application/ms-tnef"));
eml.Save("A.eml", FileCompatibilityMode.PreserveTnefAttachments);

Hi Kashif,

Thank you for your answer!
Is there a way to save data into the winmail.dat without adding an attachment (like the jpeg in your example)?
Roi

Hi Roi,


I have checked all the available documents and am afraid to share that I could not find any other appropriate method to add data to winmail.dat without the attachments. You may add any byte array data to winmail.dat along with some name as attachment which seems to fulfill most of the requirements.

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