How to send a test email between any users in Exchange/Office 365
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.
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.
For an Exchange admin to send test emails from one user to another, the following steps need to be performed:
- Log on as an administrator (Exchange admin permissions are required) to your Exchange server and open the Exchange Management Shell.
- Execute the following cmdlet:
Send-MailMessage -From "user-A@my-company.com" -To "email@example.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.
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.
- Connect to your Office 365 via PowerShell, as described in our Knowledge Base article.
- Run the following command:
Add-RecipientPermission "user-B@my-company.com" -AccessRights SendAs -Trustee "firstname.lastname@example.org"
This command assigns the SendAs permission to yourself (you are the Trustee) and specifies the target recipient (User B). Learn more
- 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 "email@example.com" -Subject "Test Message" -Body "This is a test message." -SmtpServer "smtp.office365.com" -UseSsl -Port 587 -Credential $LiveCredThis 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).
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
|Related products:||CodeTwo Email Signatures for Office 365 1.x, CodeTwo Exchange Rules 2007 4.x, CodeTwo Exchange Rules 2010 3.x, CodeTwo Exchange Rules 2013 2.x, CodeTwo Exchange Rules 2016 1.x, CodeTwo Exchange Rules 2019 1.x, CodeTwo Exchange Rules Pro 2.x|