How to send a test email between any users in Exchange/Office 365

Problem:

You want to send an email message from one user to another, without the need to access the mailboxes of these users. This is helpful for testing purposes. For example, you would like to send a test email from a specific user to yourself to examine how email rules are executed in your organization.

Solution:

Usually, if you want to send a message from another person's mailbox, you need to do it directly from this mailbox. However, if you're an admin of an Exchange on-premises / Office 365 organization and you have sufficient permissions, you can use Windows PowerShell to send emails between various users in your environment without knowing their mail account credentials. This can be achieved via the Send-MailMessage command. Click the links below to learn how to use this command in different Exchange environments.

On-premises Microsoft Exchange

For an Exchange admin to send test emails from one user to another, the following steps need to be performed:

  1. Log on as an administrator (Exchange admin permissions are required) to your Exchange server and open the ems Exchange Management Shell.
  2. Execute the following cmdlet:
    Send-MailMessage -From "user-A@my-company.com" -To "admin@my-company.com" -Subject "Test Message" -Body "This is a test message." -SmtpServer $env:userdnsdomain

This command sends a message from User A to you (admin), with the following subject: Test Message and body: This is a test message. The -Body parameter is optional. The -SmtpServer parameter is set to point to the domain of the user logged on to this Exchange server.

To learn about other parameters that can be used in the Send-MailMessage cmdlet, see this Microsoft article.

Office 365 (Exchange Online)

If you're an Office 365 (Exchange Online) admin and you want to send test emails between any mailboxes within your organization, you need to add appropriate permissions to your admin account first. After that, you can use the Send-MailMessage command in a similar way as described for on-premises mail servers. The entire procedure is described in the steps below.

  1. Connect to your Office 365 via PowerShell, as described in our Knowledge Base article.
  2. Run the following command:
    Add-RecipientPermission "user-B@my-company.com" -AccessRights SendAs -Trustee "admin@my-company.com"

    This command assigns the SendAs permission to yourself (you are the Trustee) and specifies the target recipient (User B). Learn more

  3. Now you can send emails from User B to someone else (e.g. yourself) by running the PowerShell command below:
    Send-MailMessage -From "user-B@my-company.com" -To "admin@my-company.com" -Subject "Test Message" -Body "This is a test message." -SmtpServer "smtp.office365.com" -UseSsl -Port 587 -Credential $LiveCred
    This command sends a message from User B to you (admin), with the following subject: Test Message and body: This is a test message. The -Body parameter is optional (see this article to learn more about the parameters).

    Warning

    If you followed our KB article to connect to your Office 365, the $LiveCred variable refers to your admin's credentials. If you have not defined this variable, you can do so by running the following cmdlet:

    $LiveCred = Get-Credential