向mailchimp中的列表添加新的订阅者

本文关键字:列表 mailchimp 添加 | 更新日期: 2023-09-27 18:15:59

我想知道如何使用asp.net向mailchimp列表添加新的订阅者。

下面是我在这个问题上什么都不做的代码:

var entry = new Dictionary<string, object>();
entry.Add( "FNAME", "x");
entry.Add( "LNAME", "y" );
var lsi=new listSubscribeInput(apiKey,listId,"xyz@abc.com",entry);
var ls=new listSubscribe(lsi);
ls.Execute();

向mailchimp中的列表添加新的订阅者

使用最新的API(1.3),您可以使用以下命令向列表添加订阅者:

// Subscribe the provided email to a list. 
listSubscribe(string apikey, string id, string email_address, array merge_vars,
    string email_type, bool double_optin, bool update_existing,
    bool replace_interests, bool send_welcome);

查看MailChimp API

在c#中实现是这样的:

        var options = new List.SubscribeOptions{DoubleOptIn = true,EmailType = List.EmailType.Html,SendWelcome = false};
        var merges = new List<List.Merges> { new List.Merges("john@provider.com", List.EmailType.Html) { { "FNAME", "John" }, { "LNAME", "Smith" } } };
        var mcApi = new MCApi(apiKey, false);
        mcApi.ListBatchSubscribe(listId, merges, options);

这个解决方案对我很有效。添加到引用MailChimp.Net.dll你可以定义一个接口,比如

IMailChimpManager manager = new MailChimpManager(ConfigurationManager.AppSettings["MailChimpApiKey"].ToString());

您可以在您的MailChimp列表中添加或更新您的客户端

                Member m = await manager.Members.AddOrUpdateAsync(ConfigurationManager.AppSettings["MailChimpListId"].ToString(), new Member { EmailAddress = _email, EmailType = "html", Status = Status.Pending});
            m = await manager.Members.AddOrUpdateAsync(ConfigurationManager.AppSettings["MailChimpListId"].ToString(), new Member { EmailAddress = _email, EmailType = "html", Status = Status.Subscribed });