我需要向单身人士发送电子邮件,因为我之前的电子邮件不再与我联系,所以我需要使用MailChimp。
有关MailChimp的任何代码和帮助?我正在使用asp.net。
答案 0 :(得分:0)
您需要在aspx页面中有一个订阅按钮
<asp:Button ID="btnSubscribe" CssClass="btn btn-default" OnClick="btnSubscribe_Click" runat="server" Text="Go" />
在CodeBehind
除了Keys之外,您还需要拥有需要引用项目的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;
}
}