22

I want to send email through MailChimp. How to do this in .Net?

Does any one have sample code?

0

2 Answers 2

16

The example below will send a opt-in email:

First install the NuGet package: Install-Package mcapi.net

    static void Main(string[] args)
    {
        const string apiKey = "6ea5e2e61844608937376d514-us2";   // Replace it before
        const string listId = "y657cb2495";                      // Replace it before

        var options = new List.SubscribeOptions();
        options.DoubleOptIn = true;
        options.EmailType = List.EmailType.Html;
        options.SendWelcome = false;

        var mergeText = new List.Merges("[email protected]", List.EmailType.Text)
                    {
                        {"FNAME", "John"},
                        {"LNAME", "Smith"}
                    };
        var merges = new List<List.Merges> { mergeText };

        var mcApi = new MCApi(apiKey, false);
        var batchSubscribe = mcApi.ListBatchSubscribe(listId, merges, options);

        if (batchSubscribe.Errors.Count > 0)
            Console.WriteLine("Error:{0}", batchSubscribe.Errors[0].Message);
        else
            Console.WriteLine("Success");

        Console.ReadKey();
    }
3
  • 1
    This should be the correct answer. By far the fastest and easiest way.
    – Serj Sagan
    Jul 23, 2013 at 3:25
  • 1
    fiddler indicates this is sending to v1.3 of the api and with 3.0 now live the prior versions will not be supported after 2016. oh and it didnt appear to work anyway
    – wal
    Oct 19, 2016 at 12:17
  • see answer by @Pranav Singh way below
    – wal
    Oct 19, 2016 at 12:26
3

Do Check out https://github.com/danesparza/MailChimp.NET by Dan Esparza You can install the package by using Package Manager Console

Install-Package MailChimp.NET

Code example

MailChimpManager mc = new MailChimpManager("YourApiKeyHere-us2");
ListResult lists = mc.GetLists();

For email sending and stats, Mailchimp offers Mandrill by Shawn Mclean https://github.com/shawnmclean/Mandrill-dotnet

You can install Mandrill using

Install-Package Mandrill

Code example

MandrillApi api = new MandrillApi("xxxxx-xxxx-xxxx-xxxx");
UserInfo info = await api.UserInfo();
1
  • Dan Esparza now has a note on that project page to check out the v3 one by Brandon Seydel, (noted in Pranav's answer) since that's only for the v2.0 API which has been deprecated.
    – ahwm
    May 26, 2017 at 16:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.