Save message by the last attachmentname (which is not a picture )

The Exchange service EEAttachments can save your attachments or mails automatically to your file-system and process it by your own scripts.
Post Reply
User avatar
Sven
Site Admin
Posts: 1297
Joined: Sun Jan 06, 2008 9:54 pm
Contact:

Save message by the last attachmentname (which is not a picture )

Post by Sven » Mon Apr 08, 2019 3:42 pm

Hello,

I just made a script for somebody which can save the eMail file with a filename from the attachment of it.
Here is it for the case that somebody needs it:

Code: Select all


Import-Module -Name 'C:\Program Files\Somebytes\EEAttachments\Microsoft.Exchange.WebServices.dll'
$item = Get-Variable -Name mailitem -ValueOnly
$psPropertySet = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.ItemSchema]::Attachments)  
$item.Load($psPropertySet)
$attname = "unknown"
foreach($a in $item.Attachments)
{
    if (!($attname.EndsWith("jpg")) -or ($attname.EndsWith("png")))
	{
		$attname =[IO.Path]::GetFileNameWithoutExtension($a.Name)
	}
}
$eml = Get-Variable -Name emlfile -ValueOnly
$emlfile = Get-ChildItem $eml 
$newfilename = $emlfile.DirectoryName + "\" + $attname  +".eml" 
move $eml $newfilename


Post Reply