Book Image

Microsoft Exchange 2010 PowerShell Cookbook

Book Image

Microsoft Exchange 2010 PowerShell Cookbook

Overview of this book

Table of Contents (22 chapters)
Microsoft Exchange 2010 PowerShell Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Sending e-mail messages with EWS


As we saw back in Chapter 2, Exchange Management Shell Common Tasks, we can use the built-in PowerShell v2 cmdlet Send-MailMessage to send e-mail messages. This can be a useful tool when writing scripts that need to send notifications, but the EWS Managed API has several distinct advantages over this approach. In this recipe, we'll take a look at how to send e-mail messages through EWS and why this might be a better option for organizations that have an Exchange infrastructure in place.

How to do it...

  1. First, we'll import the EWS Managed API assembly, create an instance of the ExchangeService class, and set the EWS end-point using AutoDiscover:

    Add-Type -Path C:\EWS\Microsoft.Exchange.WebServices.dll
    $svc = New-Object `
    -TypeName Microsoft.Exchange.WebServices.Data.ExchangeService
    $svc.AutoDiscoverUrl("[email protected]")
  2. Next, we'll create an instance of the EmailMessage class:

    $msg = New-Object `
    -TypeName Microsoft.Exchange.WebServices.Data.EmailMessage...