Sending Email With MailChimp With C#



Last updated: January 28th, 2024

Background

Despite the countless ways people can get notifications, email is still a valuable way to maintain a relationship with your users and customers. MailChimp's API allows the building of lists that can contain custom fields for personalized email messages. MailChimp also manages the IP addresses used for sending to ensure higher deliverability than may be possible for many companies.

The NuGet package I am using with MailChimp is: MailChimp.Net.V3 and the GitHub page for it is here. To use the API, you need an API key which is obtained from MailChimp's portal.

Workflow Options

Using MailChimp's API for sending email means that you will need to synchronize your own customer data with a copy in MailChimp. MailChimp needs to know if the user is subscribed or not, as well as their email address. The other fields, such as name, address, age, and so on are all optional. You can create your own "merge fields" with the API which can be any data of type string, number, date, image URL, etc.

Creating merge fields example:

Once you have created your merge fields, you can start populating the list with actual customer data. You can always add more merge fields later, if you need.

One option to sync your customer data is to set some type of (daily) routine where you use the Batch Operation API. By using this, you can send up to 500 operations per request to be processed. This is a useful option if you need to send all of your requests quickly, such as in an AWS Lambda Function.

This is a batch request method to send a list of users:

A better approach than trying to sync your entire user list every day or so is to update each record as needed. Not only is this going to allow you to communicate with your users in a more timely fashion because of the fresher data, but it will prevent sending emails to users who have opted out sooner than your sync process (because it runs only daily or so). Updating an entire user list is slow and most data is not changing frequently enough to justify this approach beyond an initial import. Therefore, if possible update each user in MailChimp when they make updates to their data. This can be done by adding a message to a queue which can be processed by your custom MailChimp service.

Sending Emails and Managing Customers

Typically, a marketing department will be using the actual features inside of the MailChimp portal. As a developer, the goal is to give them the best data to act on for any kind of conditions and formatting they come up with. By automating the ability to add new merge fields and having a process in place that will automatically update the MailChimp list, the marketing people will have everything they need to send emails to customers.

One important note on managing the customers I have noticed was related to storing the subscription. Your own customer database may have all kinds of settings for keeping track of which emails your customer want to get, if any. Each of these settings can correspond to a different MailChimp list. Also, a global setting for emails is useful. In all of these cases, remember that there is only one version of truth, that is your customer database. It is your responsibility as a developer to make sure these settings are persisted to MailChimp's list(s) as quickly as possible to ensure expected delivery.



Join my email list!



ryan
About Me

With 15 years in tech, I've excelled as a senior software engineer, specializing in ASP.NET, C#, SQL, Azure, and front-end technologies. I've led diverse projects across various sectors, from startups to global corporations, particularly during my decade in the San Francisco Bay Area.


Sign Up With SoftSys Hosting! (My host)