簡體   English   中英

Powershell EWS上傳eml

[英]Powershell EWS upload eml

我有這段代碼可以上傳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和附件。

編輯解決方案: 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")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM