我想通过 MailChimp 发送电子邮件。如何在.Net中做到这一点?
有人有示例代码吗?
谢谢。
下面的示例将发送一封选择加入的电子邮件:
首先安装 NuGet 包:Install-Package mcapi.net
static void Main(string[] args)
{
const string apiKey = "6ea5e2e61844608937376d514-us2"; // Replace it before
const string listId = "y657cb2495"; // Replace it before
var options = new List.SubscribeOptions();
options.DoubleOptIn = true;
options.EmailType = List.EmailType.Html;
options.SendWelcome = false;
var mergeText = new List.Merges("email@provider.com", List.EmailType.Text)
{
{"FNAME", "John"},
{"LNAME", "Smith"}
};
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);
else
Console.WriteLine("Success");
Console.ReadKey();
}
看看 CodePlex 上的 PerceptiveMCAPI:
PerceptiveMCAPI - 由 Perceptive Logic 用 C# 编写的 MailChimp Api 的 .NET 友好包装器.
对于最新 的Mail Chimp 3.0 API的支持,您可以在以下位置找到 .Net 的包装器:
MailChimp.Net - Mail Chimp 3.0 包装器
你可以在 CodePlex 上试试这个:
请查看Dan Esparza的https://github.com/danesparza/MailChimp.NET 您可以使用包管理器控制台安装包
安装包 MailChimp.NET
代码示例
MailChimpManager mc = new MailChimpManager("YourApiKeyHere-us2"); ListResult 列表 = mc.GetLists();
对于电子邮件发送和统计,Mailchimp提供了Shawn Mclean的Mandrill https://github.com/shawnmclean/Mandrill-dotnet
您可以使用安装 Mandrill
安装包 Mandrill
代码示例
MandrillApi api = new MandrillApi("xxxxx-xxxx-xxxx-xxxx"); 用户信息信息 = 等待 api.UserInfo();