예제 #1
0
        public JsonResult GetListMailChimp()
        {
            IMailChimpManager mailChimpManager = new MailChimp.MailChimpManager(Session["ApiToken"].ToString());
            var list = mailChimpManager.GetLists(null, 0, 100, "", "");

            return(Json(new SelectList(list.Data, "Id", "Name")));
        }
        static void Main(string[] args)
        {
            IMailChimpManager mailChimpManager = new MailChimpManager(config.api_key);

            Task <IEnumerable <List> > ListTask = GetList(mailChimpManager);

            ListTask.Wait();
            var ListCollection = ListTask.Result;

            foreach (var value in ListCollection)
            {
                Console.WriteLine(value.Id + " Web_id: " + value.WebId + " Name: " + value.Name);
            }

            Task <IEnumerable <Campaign> > CampaignTask = GetAllCampaign(mailChimpManager);

            CampaignTask.Wait();
            var CampaignCollection = CampaignTask.Result;

            foreach (var value in CampaignCollection)
            {
                Console.WriteLine(value.Id + " Web_id: " + value.WebId + " Created Time: " + value.CreateTime + " Title Name: " + value.Settings.Title);
            }

            Console.ReadKey();
        }
예제 #3
0
        private bool ListIsValid(string idCampaign)
        {
            bool   result = false;
            string apiKey = string.Empty;
            string list   = string.Empty;

            try
            {
                apiKey = GetSetting("ApiKey", idCampaign);
                list   = GetSetting("List", idCampaign);

                IMailChimpManager mailChimpManager = new MailChimp.MailChimpManager(apiKey);
                var lista = mailChimpManager.GetLists(null, 0, 100, "", "");
                foreach (var item in lista.Data)
                {
                    if (item.Id == list)
                    {
                        result = true;
                    }
                }
            }
            catch (Exception e)
            {
                var messageException = telemetria.MakeMessageException(e, System.Reflection.MethodBase.GetCurrentMethod().Name);
                telemetria.Critical(messageException);
            }
            return(result);
        }
예제 #4
0
        public bool ValidateApiToken(string ApiToken)
        {
            bool result = false;
            IMailChimpManager mailChimpManager = new MailChimp.MailChimpManager(ApiToken);
            var message = mailChimpManager.Ping();

            result = message != null;
            return(result);
        }
예제 #5
0
        public SelectList GetListFromMailChimp(string ApiToken)
        {
            SelectList result = null;

            if (ApiToken != string.Empty)
            {
                IMailChimpManager mailChimpManager = new MailChimp.MailChimpManager(ApiToken);
                var list = mailChimpManager.GetLists(null, 0, 100, "", "");
                result = new SelectList(list.Data, "Id", "Name");
            }
            return(result);
        }
예제 #6
0
        public JsonResult GetTagMailChimp()
        {
            IMailChimpManager mailChimpManager = new MailChimp.MailChimpManager(Session["ApiToken"].ToString());

            MailChimp.Templates.TemplateTypes tt = new MailChimp.Templates.TemplateTypes()
            {
                Base = true, Gallery = true, User = true
            };
            MailChimp.Templates.TemplateFilters tf = new MailChimp.Templates.TemplateFilters()
            {
                IncludeDragAndDrop = true
            };

            var list = mailChimpManager.GetTemplates(tt, tf);

            return(Json(new SelectList(list.UserTemplates, "TemplateID", "Name")));
        }
예제 #7
0
        public string GetSubscribersMailChimp(string ApiToken, string Id)
        {
            string subscribers = string.Empty;

            if (ApiToken != string.Empty)
            {
                IMailChimpManager mailChimpManager = new MailChimp.MailChimpManager(ApiToken);
                var list = mailChimpManager.GetLists(null, 0, 100, "", "");
                foreach (var item in list.Data)
                {
                    if (item.Id == Id)
                    {
                        subscribers = item.Stats.MemberCount.ToString();
                    }
                }
            }
            return(subscribers);
        }
예제 #8
0
        public SelectList GetTemplatesFromMailChimp(string ApiToken)
        {
            SelectList result = null;

            if (ApiToken != string.Empty)
            {
                IMailChimpManager mailChimpManager   = new MailChimp.MailChimpManager(ApiToken);
                MailChimp.Templates.TemplateTypes tt = new MailChimp.Templates.TemplateTypes()
                {
                    Base = true, Gallery = true, User = true
                };
                MailChimp.Templates.TemplateFilters tf = new MailChimp.Templates.TemplateFilters()
                {
                    IncludeDragAndDrop = true
                };

                var list = mailChimpManager.GetTemplates(tt, tf);
                result = new SelectList(list.UserTemplates, "TemplateID", "Name");
            }
            return(result);
        }
예제 #9
0
        public string SendCampaign(MailChimpCampaignRequest request)
        {
            string Id = string.Empty;

            try
            {
                CampaignCreateOptions cco = new CampaignCreateOptions()
                {
                    ListId    = request.ListId,
                    Title     = request.Name,
                    Subject   = request.Subject,
                    FromEmail = request.FromEmail,
                    FromName  = request.FromName
                };

                Dictionary <string, string> sections = new Dictionary <string, string>();


                CampaignCreateContent ccc = new CampaignCreateContent()
                {
                    Sections = sections,
                    HTML     = request.Text
                };

                IMailChimpManager mailChimpManager = new MailChimp.MailChimpManager(request.ApiKey);
                var campaignMailChimp = mailChimpManager.CreateCampaign("regular", cco, ccc, null, null);

                if (!String.IsNullOrEmpty(campaignMailChimp.Id))
                {
                    var resultSendCampaign = mailChimpManager.SendCampaign(campaignMailChimp.Id);
                    Id = resultSendCampaign.Complete ? campaignMailChimp.Id : string.Empty;
                }
            }
            catch (Exception e)
            {
                var messageException = telemetria.MakeMessageException(e, System.Reflection.MethodBase.GetCurrentMethod().Name);
                telemetria.Critical(messageException);
            }
            return(Id);
        }
예제 #10
0
        public bool ApiTokenIsValid(string idCampaign)
        {
            bool   result = false;
            string apiKey = string.Empty;

            try
            {
                apiKey = GetSetting("ApiKey", idCampaign);
                IMailChimpManager mailChimpManager = new MailChimp.MailChimpManager(apiKey);
                var lista = mailChimpManager.GetLists(null, 0, 100, "", "");
                if (lista != null)
                {
                    result = true;
                }
            }
            catch (Exception e)
            {
                var messageException = telemetria.MakeMessageException(e, System.Reflection.MethodBase.GetCurrentMethod().Name);
                telemetria.Critical(messageException);
            }
            return(result);
        }
예제 #11
0
        private bool TemplateIsValid(string idCampaign)
        {
            bool   result   = false;
            string apiKey   = string.Empty;
            string template = string.Empty;

            try
            {
                apiKey   = GetSetting("ApiKey", idCampaign);
                template = GetSetting("Template", idCampaign);

                IMailChimpManager mailChimpManager   = new MailChimp.MailChimpManager(apiKey);
                MailChimp.Templates.TemplateTypes tt = new MailChimp.Templates.TemplateTypes()
                {
                    Base = true, Gallery = true, User = true
                };
                MailChimp.Templates.TemplateFilters tf = new MailChimp.Templates.TemplateFilters()
                {
                    IncludeDragAndDrop = true
                };

                var list = mailChimpManager.GetTemplates(tt, tf);
                foreach (var tem in list.UserTemplates)
                {
                    if (tem.TemplateID.ToString() == template)
                    {
                        result = true;
                    }
                }
            }
            catch (Exception e)
            {
                var messageException = telemetria.MakeMessageException(e, System.Reflection.MethodBase.GetCurrentMethod().Name);
                telemetria.Critical(messageException);
            }
            return(result);
        }
예제 #12
0
        public JsonResult ValidateApiToken(string ApiToken, string idSite, string idProvider, string wildCard)
        {
            if (!String.IsNullOrEmpty(ApiToken) && !String.IsNullOrEmpty(idSite))
            {
                Session["ApiToken"] = ApiToken;
                Session["WildCard"] = wildCard;
                string mailingProvider = Session["PartnerSelecc"].ToString();

                var  site               = _siteService.GetSiteByIdSite(idSite);
                bool result             = false;
                bool _isPushCrew        = false;
                bool _isSubscribers     = false;
                bool _isMailChimp       = false;
                bool _isCampaignMonitor = false;
                bool _isAweber          = false;
                bool _isGetResponse     = false;
                bool _isSendGrid        = false;
                bool _isActiveCampaign  = false;
                bool _isActiveIContact  = false;
                bool _isSendinBlue      = false;
                bool _isPushEngage      = false;
                bool _isOneSignal       = false;
                bool _isMailJet         = false;

                switch (mailingProvider)
                {
                case Utils.Constants.PROVIDER_PUSH_CREW:
                    result      = Helpers.PushcrewHelper.validatePushCrewToken(ApiToken, site.URL);
                    _isPushCrew = true;
                    break;

                case Utils.Constants.PROVIDER_SUBSCRIBERS:
                    result         = Helpers.SubscribersHelper.ValidateKey(ApiToken, site.URL);
                    _isSubscribers = true;
                    break;

                case Utils.Constants.PROVIDER_MAIL_CHIMP:
                    IMailChimpManager mailChimpManager = new MailChimp.MailChimpManager(ApiToken);
                    var message = mailChimpManager.Ping();
                    result       = message != null;
                    _isMailChimp = true;
                    break;

                case Utils.Constants.PROVIDER_CAMPAIGN_MONITOR:
                    AuthenticationDetails auth = new ApiKeyAuthenticationDetails(ApiToken);
                    result             = IsValidApiKeyCampaignMonitor(auth);
                    _isCampaignMonitor = true;
                    break;

                case Utils.Constants.PROVIDER_AWEBER:
                    result    = IsValidApiKeyAWeber(ApiToken).Success;
                    _isAweber = true;
                    break;

                case Utils.Constants.PROVIDER_GETRESPONSE:
                    result         = IsValidApiKeyGetResponse(ApiToken);
                    _isGetResponse = true;
                    break;

                case Utils.Constants.PROVIDER_SEND_GRID:
                    result      = IsValidproviderapikeysendgrid(ApiToken);
                    _isSendGrid = true;
                    break;

                case Utils.Constants.PROVIDER_ACTIVE_CAMPAIGN:
                    result            = IsValidApiKeyActiveCampaign(ApiToken, wildCard);
                    _isActiveCampaign = true;
                    break;

                case Utils.Constants.PROVIDER_SENDINBLUE:
                    result        = IsValidApiKeySendingBlue(ApiToken);
                    _isSendinBlue = true;
                    break;

                case Utils.Constants.PROVIDER_PUSH_ENGAGE:
                    result        = IsValidApiKeyPushEngage(ApiToken);
                    _isPushEngage = true;
                    break;

                case Utils.Constants.PROVIDER_ONE_SIGNAL:
                    result       = IsValidApiKeyOneSignal(ApiToken);
                    _isOneSignal = true;
                    break;

                case Utils.Constants.PROVIDER_MAILJET:
                    result     = IsValidApiKeyMailJet(ApiToken, wildCard);
                    _isMailJet = true;
                    break;
                }
                return(Json(new {
                    success = result,
                    isPushCrew = _isPushCrew,
                    isSubscribers = _isSubscribers,
                    isMailChimp = _isMailChimp,
                    isCampaignMonitor = _isCampaignMonitor,
                    isAweber = _isAweber,
                    isGetResponse = _isGetResponse,
                    isSendGrid = _isSendGrid,
                    IsActiveCampaign = _isActiveCampaign,
                    IsActiveIContact = _isActiveIContact,
                    IsSendinBlue = _isSendinBlue,
                    IsPushEngage = _isPushEngage,
                    IsOneSignal = _isOneSignal,
                    IsMailJet = _isMailJet
                }));
            }
            else
            {
                return(Json(new { error = true }));
            }
        }