How to send an attachement with EWS and powershell in memory RRS feed

  • Question

  • I'd like to send automatic emails with attachements with powershell and in memory, so I do not want to persit to hdd.

     SO any hints - did search but found nothing.

    That's my code without attachment:

    $attachment = 'Some text for my text attachment!'
    Import-Module -Name 'C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll'
    $exchVersion = new-object Microsoft.Exchange.WebServices.Data.ExchangeVersion 
    $exchService = New-Object -TypeName Microsoft.Exchange.WebServices.Data.ExchangeService -ArgumentList $exchVersion
    $exchService.AutodiscoverUrl($sender , {$true})
    $eMail = New-Object -TypeName Microsoft.Exchange.WebServices.Data.EmailMessage -ArgumentList $exchService
    $eMail.Subject = $Subject
    $eMail.Body = $Body
    $eMail.ToRecipients.Add($Recipient) | Out-Null

    thanks in advance!

    Monday, December 10, 2018 3:14 PM

All replies

  • If you look at the third overload of the AddAttachment method it takes a Stream https://msdn.microsoft.com/en-us/library/microsoft.exchange.webservices.data.attachmentcollection.addfileattachment%28v=exchg.80%29.aspx




    Monday, December 10, 2018 11:29 PM