【问题标题】:Send email to single recipient via mailchimp通过 mailchimp 向单个收件人发送电子邮件
【发布时间】:2017-01-10 02:55:49
【问题描述】:

我需要给一个人发邮件,因为我之前的电子邮件人不在我身边,所以我需要使用 MailChimp。

关于 MailChimp 的任何代码和帮助?我正在使用 asp.net。

【问题讨论】:

  • 嗨,莫尼尔。我们在 stackoverflow 鼓励您尝试自己做。如果您遇到一些问题,那么您应该发布一个问题,其中包含您尝试过的信息和代码示例。
  • 我昨天做了研发,但还没有运气,所以帮助会很明显

标签: asp.net mailchimp email


【解决方案1】:

您需要在您的 aspx 页面中有一个订阅按钮

<asp:Button ID="btnSubscribe"  CssClass="btn btn-default" OnClick="btnSubscribe_Click" runat="server" Text="Go" />

在代码隐藏中

除了密钥之外,您还需要有 MailChimp dll 需要引用到您的项目

protected void btnSubscribe_Click(object sender, EventArgs e)
{
    try
    {
       // Keys for Mail chimp , when you signup in their site 
       // there you can get these keys and i stored them in webconfig
        string apiKey = Convert.ToString(ConfigurationManager.AppSettings["MailChimpApiKey"]);
        string listId = Convert.ToString(ConfigurationManager.AppSettings["MailChimpListId"]);

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

        var mergeText = new List.Merges(txtSubscribe.Text.Trim(), List.EmailType.Text)
                {
                    {"FNAME", "webruster"},
                    {"LNAME", "Web"}
                };
        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);
            ScriptManager.RegisterStartupScript(btnSubscribe, btnSubscribe.GetType(), "subscribe", "alert('Given email address is already subscribed, thank you!')", true);
        // ScriptManager.RegisterStartupScript(btnSubscribe, btnSubscribe.GetType(), "subscribe", "alert('"+ batchSubscribe.Errors[0].Message + @"')", true);

        else
            //      Console.WriteLine("Success");
            ScriptManager.RegisterStartupScript(btnSubscribe, btnSubscribe.GetType(), "subscribe", "alert('You are subscribed to newsletter successfully.')", true);




    }
    catch (Exception ex)
    {
        //   ErrorLogger.ClientErrorLogger(ex);
        throw ex;
    }
}

【讨论】:

  • list id 是什么意思?
  • 每个 MailChimp 列表都有一个唯一的列表 ID,集成、插件和小部件可能需要它来连接和传输订阅者数据。 List ID 由我们的系统在创建列表时生成,无法更改。 Source
猜你喜欢
  • 2013-10-30
  • 1970-01-01
  • 2011-07-14
  • 2018-07-13
  • 1970-01-01
  • 1970-01-01
  • 2014-12-15
  • 2012-05-18
相关资源
最近更新 更多