One of the most common mistakes made by developers of internal database systems is the failure to leverage existing toolsets, attempting to handle everything internally. For simple tasks, this is often the best solution. However, bulk mailing for marketing is not something your ERP system or CMS should be handling directly. There are a wide variety of bulk email services, but I’ve found MailChimp to be the most flexible of all. It has both a simple and flexible user interface as well as an API serving multiple platforms. From a security perspective, it is ALWAYS best to keep marketing people out of areas where non-marketing data may be.
I’ve written a few simple scripts to show you how to add or update information from your private database to a MailChimp server. The client system I’m working with is written in ASP.net with VB.net as the code-behind. The module being used is MailChimp.net.
Once you’ve installed the package, you can simply import the libraries
Imports MailChimp Imports MailChimp.Lists Imports MailChimp.Helper
In our case, we needed our internal database of parents to link to a mailing list. We simply made a function to search for the email in a MailChimp list, then either update it or add a new record.
Dim email As New EmailParameter Dim mc As New MailChimpManager(api) Dim list As ListResult = mc.GetLists() Dim listid As String = list.Data(0).Id Dim mergeVars As New MergeVar mergeVars("FNAME") = txtParent1First.Text mergeVars("LNAME") = txtParent1Last.Text mergeVars("new-email") = txtParent1Email.Text Dim match As Matches = mc.SearchMembers(txtParent1EmailOriginal.Text, listid) If match.ExactMatches.Members.Count = 0 Then email.Email = txtParent1Email.Text mc.Subscribe(listid, email, mergeVars, "html", False) Else email.Email = txtParent1EmailOriginal.Text mc.UpdateMember(listid, email, mergeVars) txtParent1EmailOriginal.Text = txtParent1Email.Text End If
So here’s what’s happening:
MailChip keeps emails in lists. So each list has subscribers. Each subscriber has a key, but the standard “find” (SearchMembers) is by email.
All the variables associated with the record as held in a custom object called “MergeVar”
In our case, we are simply updating the first/last names of the parents as well as their emails.