【问题标题】:MailChimp Integaration with MVC 5MailChimp 与 MVC 5 的集成
【发布时间】:2022-04-05 17:35:11
【问题描述】:

我正在做一个 MVC5 项目,客户有兴趣使用 MailChimp 发送电子邮件。我已经探索了 MailChimp 和包装器( MailChimp.NET )并在我的项目中进行了尝试。例如,我也测试了 REST API,它似乎可以工作;我能够使用 REST API 获取列表和模板。但是,我仍然在通过 MailChimp 发送电子邮件时遇到问题。

到目前为止,我已经尝试了以下代码及其工作。现在我想向新注册的用户发送一封电子邮件。请给我详细的代码示例,我该如何实现这一点,因为我完全被这里打动了..

  var apiKey = "myapikey-us11";
    var listId = "mylistid"; 
    var subscribeRequest = new
                    {
                        apikey = apiKey,
                        id = listId,
                        email = new
                        {
                            email = "muhammad.waqas@seventechnology.co.uk"
                        },
                        double_optin = true,
                    };
    var requestJson = JsonConvert.SerializeObject(subscribeRequest);
    var reqresult = CallMailChimpApi("lists/", requestJson);

CallMailChimApi

    private static string CallMailChimpApi(string method, string requestJson)
    {
       var endpoint = String.Format("https://{0}.api.mailchimp.com/3.0/{1}", "us11", method);
        var wc = new WebClient();

        try
        {
            return wc.UploadString(endpoint, requestJson);
        }
        catch (WebException we)
        {
            using (var sr = new      StreamReader(we.Response.GetResponseStream()))
            {
                return sr.ReadToEnd();
            }
        }
    }

【问题讨论】:

    标签: c# asp.net-mvc mailchimp


    【解决方案1】:

    我使用了这个功能,它成功了 公共无效 SendEmailByApiMailChimp () { 尝试 { 字符串 UserEmail = " Example@gmail.com "; MailChimpManager mc = new MailChimpManager("16d***********-us14"); 电子邮件参数电子邮件 = 新电子邮件参数() { 电子邮件 = 用户电子邮件 };

                EmailParameter resulte = mc.Subscribe("yourlistnumber", email);
                var test = resulte;
            }
            catch (Exception ex)
            {
                var ters = ex;
            }
           
        }
    

    【讨论】:

      猜你喜欢
      • 2018-05-29
      • 2018-11-02
      • 2016-06-01
      • 2016-01-10
      • 2021-02-25
      • 2020-12-18
      • 2014-04-06
      • 2019-03-19
      • 1970-01-01
      相关资源
      最近更新 更多