微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

我正在尝试使用 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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。