1

我有这个代码来上传 EML 文件进行交换。

#Upload Eml Sample  

$folderid= new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$MailboxName)     
$Inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)  
#Crete Email Object  
$emUploadEmail = new-object Microsoft.Exchange.WebServices.Data.EmailMessage($service)  
#Read File  
[byte[]]$bdBinaryData1 =  get-content -encoding byte "C:\temp\exportedmail.eml"  
#Set Mime Content in Message  
$emUploadEmail.MimeContent = new-object Microsoft.Exchange.WebServices.Data.MimeContent("us-ascii", $bdBinaryData1);  
#Set Sent Message Flags which means message wont appear as a Draft  
$PR_Flags = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(3591, [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Integer);  
$emUploadEmail.SetExtendedProperty($PR_Flags,"1")  
$emUploadEmail.Save($Inbox.Id) 

当我尝试上传带有附件的 EML 文件时,它会使运行脚本的计算机崩溃。它占用了所有的内存。如何修改上面的代码以上传 eml 和附件。

4

1 回答 1

0

编辑解决方案: Glen Scales在这里提供了一个解决方案:

http://gsexdev.blogspot.com/2012/02/ews-managed-api-and-powershell-how-to_22.html#!/2012/02/ews-managed-api-and-powershell-how-to_22。 html

替换获取内容:

[byte[]]$bdBinaryData1 = get-content -encoding byte "C:\temp\exportedmail.eml"

[byte[]]$bdBinaryData1 = [System.IO.File]::ReadAllBytes("C:\temp\exportedmail.eml")

于 2013-09-12T20:13:55.233 回答