exchange server - Powershell EWS upload eml -
i have code upload eml files exchange.
#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 means message wont appear 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)
when try upload eml file attachment crash computer running script. takes memory. how can modify code above upload eml , attachment.
edit solution: glen scales provides solution here:
replace get-content:
[byte[]]$bdbinarydata1 = get-content -encoding byte "c:\temp\exportedmail.eml"
with
[byte[]]$bdbinarydata1 = [system.io.file]::readallbytes("c:\temp\exportedmail.eml")
Comments
Post a Comment