MailChimp与MVC 5的集成
本文关键字:集成 MVC MailChimp | 更新日期: 2023-09-27 18:17:36
我正在做一个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();
}
}
}
我使用这个函数,它工作成功SendEmailByApiMailChimp (){试一试{string UserEmail = "Exemple@gmail.com";MailChimpManager mc = new MailChimpManager("16d***********-us14");email = new EmailParameter(){Email = UserEmail
}; EmailParameter resulte = mc.Subscribe("yourlistnumber", email);
var test = resulte;
}
catch (Exception ex)
{
var ters = ex;
}
}