如何将Outlook MailItem转换为Stream

时间:2012-08-28 07:50:15

标签: c# stream office-interop

我想将Microsoft.Office.Interop.Outlook.MailItem转换为Stream。我怎样才能做到这一点?下面的代码显示了我如何构建Outlook MailItem。

Microsoft.Office.Interop.Outlook.Application outlookApp =
    new Microsoft.Office.Interop.Outlook.Application();

Microsoft.Office.Interop.Outlook.MailItem mailItem = 
    (Microsoft.Office.Interop.Outlook.MailItem)outlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

Microsoft.Office.Interop.Outlook.NameSpace mapiNameSpace = 
    outlookApp.GetNamespace("MAPI");

mailItem.Subject = .....
mailItem.To = ....

就像我将数据分配给Outlook MailItem一样。如何将此MailItem转换为流?

1 个答案:

答案 0 :(得分:0)

创建一个System.Net.Mail.MailMessage对象,将属性从Outlook.MailItem复制到该对象并保存。

var msg = new System.Net.Mail.MailMessage();
msg.From = new System.Net.Mail.MailAddress("aaa@bb.com");
msg.To.Add("cccc@ddd.net");
msg.Subject = "test test";

var client = new System.Net.Mail.SmtpClient();
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.SpecifiedPickupDirectory;
client.PickupDirectoryLocation = @"c:\temp";
client.Send(msg);