2012-08-28 92 views
0

我想將Microsoft.Office.Interop.Outlook.MailItem轉換爲Stream。我怎樣才能做到這一點?下面的代碼顯示了我如何構建Outlook MailItem。如何將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轉換爲流?

+0

你是什麼意思「將郵件轉換爲流」? –

+0

我的意思是如何將mailitem轉換爲字節? – user1463065

+0

哪部分? MailItem由許多字段組成。你打算如何處理這個流? – BrainPicker

回答

0

創建一個System.Net.Mail.MailMessage對象,從Outlook.MailItem複製屬性並保存。

var msg = new System.Net.Mail.MailMessage(); 
msg.From = new System.Net.Mail.MailAddress("[email protected]"); 
msg.To.Add("[email protected]"); 
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);