Click here to Skip to main content
15,895,656 members
Please Sign up or sign in to vote.
1.12/5 (3 votes)
See more:
Hi, I want to send email through MailChimp. How to do this in .Net?

Has any one have help code??????

Thanks.
Posted
Updated 1-Aug-22 6:29am

I would start by doing some reading: MailChimp support resources[^]
 
Share this answer
 
 
Share this answer
 
Install the NuGet package from the package manager console:

Install-Package MailChimp.Net.V3

Using it in code
C#
IMailChimpManager manager = new MailChimpManager(apiKey); //if you have it in code

<add key="MailChimpApiKey" value="apiKEY" />
IMailChimpManager manager = new MailChimpManager(); //if you have it in config
Examples

// Instantiate new manager
IMailChimpManager mailChimpManager = new MailChimpManager(apiKey);
Getting all lists:

var mailChimpListCollection = await this.mailChimpManager.Lists.GetAllAsync().ConfigureAwait(false);
Getting 50 Lists:

var mailChimpListCollection = await this.mailChimpManager.Lists.GetAllAsync(new ListRequest
                                                               {
                                                                   Limit = 50
                                                               }).ConfigureAwait(false);
Getting Users from List:

var listId = "TestListId";
await this.mailChimpManager.Members.GetAllAsync(listId).ConfigureAwait(false);
Adding User To List

var listId = "TestListId";
var member = new Member { EmailAddress = $"githubTestAccount@test.com", Status = Status.Subscribed };
member.MergeFields.Add("FNAME", "HOLY");
member.MergeFields.Add("LNAME", "COW");
await this.mailChimpManager.Members.AddOrUpdateAsync(listId, member);
 
Share this answer
 
I wrote an article on a simple way up adding subscribers to a list using:
VB
Dim mailchimp As New ZmailChimp
      Dim ListId$ = "9b2e63f0b9"   'List Sage' List
      Dim email$ = "samsmith20@anymail.com" '"sam19@postcodelite.com"
      Dim fieldListOnAdd = "FNAME,Sam,LNAME,Smith,MTYPE,User,MID,631637"
      Dim fieldListOnUpdate = "FNAME,Sam,LNAME,Smith,MID,631637"  'Don't change MTYPE
      'Put on 'Sage One' and 'Sage 50' group
      Dim groupList = "407da9f47d,05086211ba"

      With mailchimp
         .API$ = "46cMailChimpAPIKeyd1de-us14" 'MailChimp API key
         .dataCenter$ = "us14"  'Last 4 letters of API key
         .password$ = "Password!"
         MsgBox(.addSubscriber(ListId$, email, fieldListOnAdd, fieldListOnUpdate, groupList))
      End With
      mailchimp = Nothing


see:http://www.codeproject.com/Tips/1140339/Mail-Chimp-Add-Update-e-mail-to-List-and-Subscribe
this may save someone some time
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900