【发布时间】: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