如何在c# /. net中集成MailChimp

本文关键字:集成 MailChimp net | 更新日期: 2023-09-27 17:53:27

我想通过MailChimp发送电子邮件。如何在。net中做到这一点?

有示例代码吗?

如何在c# /. net中集成MailChimp

下面的示例将发送一封选择加入的电子邮件:

首先安装NuGet包: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@provider.com", 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();
    }

Do Check out https://github.com/danesparza/MailChimp.NET by Dan Esparza您可以使用 package Manager Console

安装包<>之前安装包MailChimp的。净之前

代码示例

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

对于电子邮件发送和统计,Mailchimp提供MandrillShawn Mclean https://github.com/shawnmclean/Mandrill-dotnet

你可以使用

安装Mandrill<>之前安装包山魈之前

代码示例

MandrillApi api = new MandrillApi("xxxx -xxxx-xxxx-xxxx");UserInfo info = await api.UserInfo();