如何使用 MailChimp.Net 通过 C# 向电子邮件发送简单的电子邮件?

时间:2021-01-27 16:22:15

标签: c# .net-core mailchimp mailchimp-api-v3.0

我正在尝试使用 MailChimp 发送电子邮件。我们的项目是 .net 核心应用程序,但这里出了点问题。也许,我做错了什么,但我找不到确切的解决方案。 mailchimp.net 中没有简单的邮件发送。如何使用 MailChimp.net 发送电子邮件?

    static async void Run()
        {
            MailChimpManager _mailChimpManager = new MailChimpManager(ApiKey);
            var list = _mailChimpManager.Lists.AddOrUpdateAsync(new List() { Contact = new Contact() { Address1 = "test5" }, });
            var r = _mailChimpManager.Lists.GetAllAsync().GetAwaiter();
            var m = _mailChimpManager.Members.AddOrUpdateAsync(list.Id.ToString(),
                new Member
                {
                    EmailAddress = "test@gmail.com",
                    EmailType = "html",
                    Status = Status.Subscribed
                });


            var _campaignSettings = new Setting
            {
                ReplyTo = "test1@yahoo.com",
                FromName = "The name that others will see when they receive the email",
                Title = "Your campaign title",
                SubjectLine = "The email subject",
            };
            var campaign = _mailChimpManager.Campaigns.AddAsync(new Campaign
            {
                Settings = _campaignSettings,
                Recipients = new Recipient { ListId = list.Id.ToString() },
                Type = CampaignType.Regular
            }).Result;
            var timeStr = DateTime.Now.ToString();
            var content = _mailChimpManager.Content.AddOrUpdateAsync(
             campaign.Id,
             new ContentRequest()
             {
                 Template = new ContentTemplate
                 {
                     Id = TemplateId,
                     Sections = new Dictionary<string, object>()
                                                {
                                       { "body_content", "<h1>Test</h1>" },
                                       { "preheader_leftcol_content", $"<p>{timeStr}</p>" }
                                                }
                 }
             }).Result;
            _mailChimpManager.Campaigns.SendAsync(campaign.Id).Wait();



        }

enter image description here

0 个答案:

没有答案