![](/img/trans.png)
[英]How to export mail message to EML or MSG file with PowerShell and EWS part 2
[英]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在此處提供解決方案:
替換獲取內容:
[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.