MailChimp Integration with MVC 5

I am working on a MVC5 project, a client is interested in using MailChimp to send emails. I studied MailChimp and wrappers (MailChimp.NET) and tried in my project. I tested the REST API and, for example, worked, for example; I was able to capture lists and templates using the REST API. But, nevertheless, I am having problems sending email through MailChimp.

So far I have tried using the following code and its operation. Now I want to send an email to a new registered user. Please give me a detailed code example that how I can achieve this because I am completely amazed here.

  var apiKey = "myapikey-us11";
    var listId = "mylistid"; 
    var subscribeRequest = new
                    {
                        apikey = apiKey,
                        id = listId,
                        email = new
                        {
                            email = "muhammad.waqas@seventechnology.co.uk"
                        },
                        double_optin = true,
                    };
    var requestJson = JsonConvert.SerializeObject(subscribeRequest);
    var reqresult = CallMailChimpApi("lists/", requestJson);

CallMailChimApi

    private static string CallMailChimpApi(string method, string requestJson)
    {
       var endpoint = String.Format("https://{0}.api.mailchimp.com/3.0/{1}", "us11", method);
        var wc = new WebClient();

        try
        {
            return wc.UploadString(endpoint, requestJson);
        }
        catch (WebException we)
        {
            using (var sr = new      StreamReader(we.Response.GetResponseStream()))
            {
                return sr.ReadToEnd();
            }
        }
    }
+4

Source: https://habr.com/ru/post/1611379/


All Articles