Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
258 views
in Technique[技术] by (71.8m points)

.net core - How can I use MailChimp.Net for sending simple email to an email by C#?

I am trying to send an email by using MailChimp. Our project is .net core application but something wrong here. Maybe, I am doing something wrong but I couldn't find an exact solution for that. There is no simple mail send in mailchimp.net. How can I send an email by using 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 = "[email protected]",
                    EmailType = "html",
                    Status = Status.Subscribed
                });


            var _campaignSettings = new Setting
            {
                ReplyTo = "[email protected]",
                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

question from:https://stackoverflow.com/questions/65923182/how-can-i-use-mailchimp-net-for-sending-simple-email-to-an-email-by-c

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...