我有这个代码来上传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和附件。
答案 0 :(得分:0)
编辑解决方案: Glen Scales 在此提供解决方案:
替换Get-Content:
[byte[]]$bdBinaryData1 = get-content -encoding byte "C:\temp\exportedmail.eml"
与
[byte[]]$bdBinaryData1 = [System.IO.File]::ReadAllBytes("C:\temp\exportedmail.eml")