Exchange Server 2010 brought a lot of new features to the table, and in this article we are going to cover a simple but really interesting capability of the product; the ability to send mail from the console or through PowerShell. Most of the Exchange Administrators that I know have complained about the inability to send messages from the console on previous Exchange versions. Now those admins will have to find something else to complain about because Exchange Server 2010 and PowerShell 2.0 (I will explain in a bit) brought two different ways to send messages in an easy way without opening an Outlook or Outlook Web App session!! :)
There are a few key points about Send Mail capabilities, which are as follows:
- The Send Mail feature works with any Mailbox, Contact or Group. This feature does not work with Resource Mailboxes though.
- In order to use the feature you need Outlook 2010 x64 installed on the same machine where you want to send messages.
Using Exchange Management Console
Using Exchange Management Console is really easy, just expand Recipient Configuration and right-click on a mailbox and you will see the Send Mail item on the menu or you can also use the Toolbox Actions in order to have the same item, as show in Figure 1.
As soon as you click on Send Mail a New Message of Outlook 2010 will pop up, just type in the message and click on Send (Figure 2). That is it! By the way, it’s nice to have your Outlook profile configured beforehand to avoid configuring Outlook when you want to send a message. You can take advantage of the profile configure and define signature and any other Outlook environment settings and you will be able to use those features when you receive the send mail dialog box.
Some companies don’t like the Administrator sending messages to the end-users. Let us say our company has a mail-enabled group called IT and they use that Group as default to send informational messages to the users.
The process to configure and use it is really simple. The first step is to select the account that you want to use to send messages to the users using Exchange Management Console and then click on Manage Send As permission. On the first page of the wizard click on Add… button (Figure 3) and add your user to the list (It makes sense to add the current user logged on, because it is his Outlook session that will be opened when you click on Send Mail). After that just click on Manage and then Finish.
Let us try to use the Send Mail feature again but this time we are going to click on Options menu item and then let’s click on From button and we will notice that the From: field will show up right above To: field (Figure 4). Click on it and then click on Other E-mail Address… and a new dialog box will pop up just type in the name of the mailbox that you have send as permissions on it and click OK.
Now, you can fill out the information left (Subject and the message itself) and click on Send. The user will receive a message from the account designed on the Form: field instead of the logged user.
Using Exchange Management Shell/Windows PowerShell 2.0
Actually, Windows PowerShell 2.0 is the responsible for the Send Mail feature using command line. The cmdlet called Send-MailMessage was introduced in the new version of PowerShell and it does not require Exchange Management Shell or Outlook to work which means if you have a Windows Server 2008 R2 you can use the same procedures that we are going to describe in this section.
In order to demonstrate the cmdlet usage, let’s send a message using a regular mailbox (Anderson.Patricio) and I will be sending to the other user. The most common switches are these ones:
As you can see the switches are self-explanatory, let's send a message using Exchange Management Shell using just the most common switches (Figure 5), the following syntax can be used:
Send-MailMessage –From <email@example.com> –To <Recipient@domain.com> –Subject “Test #01”-Body “Just a test message.” –SMTPServer <Server-Name> –Credential <domain\user>
If the current user is the same entered in the From switch then the –Credential switch is not required.
Because we are using a different user (Credential) a pop-up requiring the password will be displayed. Next step is to type in the password and click on OK, as show in the Figure 6.
Now it’s time to open the recipient mailbox and check if the message arrived properly. The example that we have just done is using only the required switches but we can do a lot more with that cmdlet. You always can check all available switches using man Send-MailMessage –Detailed.
A great example for the Exchange Administrator is the ability to attach files using the same cmdlet. Let’s use a simple scenario where you are the main Exchange Administrator of your organization and you have several remote locations, and you have been asked to generate a report containing a list of all mailboxes of determined server. In this kind of situation we can solve such request using a couple of cmdlets, as follows:
- First get all the mailbox information from that server and export to a CSV
Get-Mailbox -Server tor-ex-01 | select Name,Alias,ProhibitSendQuota | Export-Csv C:\Report-Tor-ex-01.csv
- Send the message using Send-MailMessage and –attachments switch
Send-MailMessage -From firstname.lastname@example.org -To Lidiana@apatricio.local -Subject "TOR-EX-01 Server User List" -Body " Hi, here is the report that you requested." -Attachments C:\Report-Tor-EX-01.csv -SmtpServer tor-ex-01 -Credential apatricio\anderson
The cmdlets used for this procedure can be seen in the Figure 7, and the message generated with an attachment can be seen in the Figure 8.
Common issues using the Send Mail feature...
Okay everything that we have seen so far was pretty easy and straight forward although you may face some issues using Send Mail on Exchange Management Shell, here are a couple of issues that I've found so far:
Issue #01: Trying to send message as Administrator
That is one of the most common errors, if you try to send messages using the administrator account it will fail. The reason of this error can be found if you enable Receive Connector logging. In order to enable it, just open Exchange Management Console, expand Server Configuration, Click on Hub Transport and click on the designated server on the right side. Then, double click on the Default Receive Connector and change change the Protocol logging level to Verbose, as shown in Figure 9.
By default the Default Receive Connector allows Authenticated Users to relay however well-known accounts are not included which means the Administrator won’t be able to send a message.
Using the logging we can validate the issue, as depicted in Figure 10. The solution is to use a regular account instead of Administrator (or any other well-known account).
Issue #02: Certificates and –UseSSL switch
By default the Send-MailMessage cmdlet does not use SSL however you can increase the security using the–UseSSL switch.
That switch will work with certficates which means that we must pay attention to the switch –SMTPServer where it cannot contain IP Address or any name that is not listed on the installed certificate on Exchange Server.
Issue #03: Self-signed Certificates...
If you are using the right name of the certificate and you are receiving the error The remote certificate is invalid according to the validation procedure. You may be using a Built-in certificate, if that is your case a solution can be achieved adding the built-in certificate to the client where you are running the cmdlet.
The process is simple just open a browser session and go to https://<Exchange-2010-Server-Name>/owa, and click on Certificate Error item and then click on View Certificates, as shown in Figure 11.
In the certificate properties page, click on Install Certificate, a new Certificate Import Wizard will be displayed, on the initial page, just click Next. In the Certificate Store page, select Place all certificates in the following store, click on Browse button. Check the option Show physical stores. Expand Trusted People and select Local Computer and click OK, as shown in Figure 12.
After that just click on Next and Finish. Now, it’s time to test and you should be okay on that task.
I will be honest, when I started to write about a simple feature like sending messages using Exchange Management Console and Shell I thought that I would not be able to write more than 10 lines but it turned out that there are a bunch of applications and tweaks that we can do to help in our exchange daily tasks.
We saw in this article how to use the Send-MailMessage cmdlet, also some workarounds for some known issues of the cmdlet and finally we saw a simple example where we can save administration time using it to send messages and reports straight from the command line.