C# and SES (Simple Email Service)

Continuing my way through some of the AWS services I’ve been consuming lately, so let’s pick up with SES (Simple Email Service).  Thousands of providers to do this just like any other quality service but again, cost, ease and already being in embedded with other PaaS components made this a strong contender when I was evaluating.  Similar to what we did with the SNS class in the previous post, I’ve taken a similar approach when wrapping SES.

The Interface

Like you are probably getting used to seeing from my approaches, we are going to build a simple interface for what our class will implement

What’s going on here.  Not much but the methods I want to provide to our clients is

  • Pass in a subject for the email
  • Provide a list of addresses or a single address
  • Is the body of the message HTML or not

I’m sure there other things a library such as this might want to do so of course you extend this even further.

The Implementation

Just like in the SNS class, the constructor takes on an IConfiguration which is injected in.  You will need an IAM user that has access to send emails.  This is again outside of the scope of this post, but feel free to message me in the comments and I’ll be happy to help you debug if I can.

The SendEmail method that takes an address as you can see just calls the overloaded version which takes an array.  So let’s briefly walk through what that method is doing.

AmazonSimpleEmailServiceClient is the SDK class that does the heavy lifting.  What our method does is build up a SendEmailRequest that can be passed into the client where the magic happens.  I’m not currently doing anything with the isHtml flag but of course you could format the message accordingly if you want to handle plain text and/or HTML.


And that’s it.  Super simple.  I’m using a more enhanced version of this @ 30M + times a day and dotnet core and AWS’ Lambda have no trouble handling that kind of volume.

Up Next

I’ll probably take a detour for my next couple of posts and then come back to Kinesis and SQS with a Lambda and C#

Thanks for reading!


About the author

Ben Pyle is a software developer who enjoys solving problems and delighting customers with right quality software. He's a husband, father to 2 boys and avid golfer. In his free time he enjoys reading, playing lots of golf and hanging out with his family doing whatever they are into.

Leave a Reply

Your email address will not be published. Required fields are marked *