Simulate User Message Sends leveraging EWS

If you’ve read any of my posts in the past, you know that I’ve got a lab at the office.  Part of this includes a handful of Exchange Servers.  To better simulate “real-world” (not stress-test) simulations, I want to send messages around the organization.  Thankfully, I’ve had some experience with Exchange Web Services (EWS) in the past.

Here’s what I came up with:

So now I’ve got the bounds of when I want to send these messages (Work hours/days) and how frequently I want to send messages.

Then I just begin a while loop when I’m in within “working hours” and repeat.

Only one account can send a message – so I grab one at random.  Then I need to select the possible recipients.  Here I’m using between 1 and 10, but you can easily change this to whatever you like.

Then I setup my impersonation user (more about that here)

Now I need to load the Exchange Web Services API into memory (download here)

Since I want the mail to go through ANY mailbox server, I elected to not use Autodiscovery.  You can choose how to do this for yourself.  Then I create the email and need some random text for the subject and body.  For this I shamelessly use the Web API available from LoremIpsum.  The last construction step is to add the attachments (if I have any) and send the message.

Putting it all together yields the following:

When running it looks something like this:

That’s it. Pretty simple, but it works.

Leave a Comment