Ejemplo n.º 1
0
        private void frmEmailCampaign_Load(object sender, EventArgs e)
        {
            try
            {
                string state = "ok";
                _accessToken = OAuth.AuthenticateFromWinProgram(ref state);

                if (string.IsNullOrEmpty(_accessToken))
                {
                    Application.Exit();
                }

                //initialize ConstantContact members
                IUserServiceContext    userServiceContext      = new UserServiceContext(_accessToken, _apiKey);
                ConstantContactFactory _constantContactFactory = new ConstantContactFactory(userServiceContext);
                _emailCampaignService         = _constantContactFactory.CreateEmailCampaignService();
                _emailCampaginScheduleService = _constantContactFactory.CreateCampaignScheduleService();
                _listService    = _constantContactFactory.CreateListService();
                _accountService = _constantContactFactory.CreateAccountService();
            }
            catch (OAuth2Exception oauthEx)
            {
                MessageBox.Show(string.Format("Authentication failure: {0}", oauthEx.Message), "Warning");
            }

            PopulateCampaignTypeList();
            PopulateListOfCountries();
            PopulateUSAndCanadaListOfStates();

            GetListOfContacts();
            PopulateEmailLists();
        }
Ejemplo n.º 2
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            _apiKey             = ConfigurationManager.AppSettings["APIKey"];
            Session["campaign"] = TextBox1.Text;
            try
            {
                string state = "ok";
                OAuth.AuthorizeFromWebApplication(HttpContext.Current
                                                  , state);


                //initialize ConstantContact members
                IUserServiceContext    userServiceContext      = new UserServiceContext(_accessToken, _apiKey);
                ConstantContactFactory _constantContactFactory = new ConstantContactFactory(userServiceContext);
                _emailCampaignService         = _constantContactFactory.CreateEmailCampaignService();
                _emailCampaginScheduleService = _constantContactFactory.CreateCampaignScheduleService();
                _listService    = _constantContactFactory.CreateListService();
                _accountService = _constantContactFactory.CreateAccountService();
            }
            catch (OAuth2Exception oauthEx)
            {
                //  MessageBox.Show(string.Format("Authentication failure: {0}", oauthEx.Message), "Warning");
            }


            //PopulateListOfCountries();
            //PopulateUSAndCanadaListOfStates();

            //GetListOfContacts();
            //PopulateEmailLists();
        }
Ejemplo n.º 3
0
        private void Initialize()
        {
            try
            {
                string state = "ok";
                if (String.IsNullOrEmpty(_emailTemplateTransformUrl))
                {
                    throw new Exception("Missing email campaign template location from configuration");
                }

                if ((String.IsNullOrEmpty(_apiKey) || String.IsNullOrEmpty(_accessToken)) && !String.IsNullOrEmpty(_emailConnectionTransformUrl))
                {
                    XDocument emailConnection = new XDocument();
                    using (System.Xml.XmlWriter writer = emailConnection.CreateWriter())
                    {
                        XslCompiledTransform emailConnectionTransform = new XslCompiledTransform();
                        emailConnectionTransform.Load(_emailConnectionTransformUrl);
                        emailConnectionTransform.Transform(XDocument.Parse("<dummy />").CreateReader(), writer);
                    }
                }

                if (String.IsNullOrEmpty(_accessToken))
                {
                    _accessToken = OAuth.AuthenticateFromWinProgram(ref state);
                }
                if (string.IsNullOrEmpty(_accessToken))
                {
                    throw new Exception("Unable to authenticate & retrieve access token");
                }

                //initialize ConstantContact members
                IUserServiceContext    userServiceContext      = new UserServiceContext(_accessToken, _apiKey);
                ConstantContactFactory _constantContactFactory = new ConstantContactFactory(userServiceContext);
                _emailCampaignService         = _constantContactFactory.CreateEmailCampaignService();
                _emailCampaginScheduleService = _constantContactFactory.CreateCampaignScheduleService();
                _listService = _constantContactFactory.CreateListService();
            }
            catch (OAuth2Exception oauthEx)
            {
                GlobalFunctions.WarnLog(string.Format("Authentication failure: {0}", oauthEx.Message));
            }
        }
Ejemplo n.º 4
0
        private string GetListService()
        {
            string _accessToken = OAuth.GetAccessTokenByCode(HttpContext.Current, Request.QueryString["code"].ToString());

            try
            {
                string _apiKey = ConfigurationManager.AppSettings["APIKey"];
                IUserServiceContext    userServiceContext      = new UserServiceContext(_accessToken, _apiKey);
                ConstantContactFactory _constantContactFactory = new ConstantContactFactory(userServiceContext);
                _listService = _constantContactFactory.CreateListService();
                //  EmailCampaign campaign = CreateCampaignFromInputs();

                List <ContactList> allcontacts = new List <ContactList>();
                contactListFromListService = _listService.GetLists(DateTime.Now.AddDays(-10));
            }
            catch (Exception ex)
            {
            }
            return(_accessToken);
        }
        public void SendCampaign()
        {
            if (ValidateFields())
            {
                var confirmResult = MessageBox.Show(CommonConstants.MandatoryFields.Alert,
                                                CommonConstants.MandatoryFields.SendCampaign,
                                                MessageBoxButtons.YesNo);
                if (confirmResult == DialogResult.Yes)
                {
                    
                    string campaignId = cmbCampaign.SelectedValue.ToString();
                    // Loading panel
                    Cursor.Current = Cursors.WaitCursor;

                    try
                    {
                        ApiKey = ConstantContactAPI;
                        AccessToken = ConstantContactToken;
                        IUserServiceContext userServiceContext = new UserServiceContext(AccessToken, ApiKey);
                        var cc = new ConstantContactFactory(userServiceContext);
                        List<SentContactList> SentContactListObj = new List<SentContactList>();
                        Contact contact = new Contact();
                        List<Contact> contactList = new List<Contact>();
                        var emailCampignService = cc.CreateEmailCampaignService();
                        var result = emailCampignService.GetCampaign(campaignId);
                        int count = 0;
                        foreach (var item in result.Lists)
                                     {
                                         SentContactList contactObj = new SentContactList();
                                         contactObj.Id = item.Id;
                                         SentContactListObj.Add(contactObj);
                                     }
                                     foreach (var item in SentContactListObj)
                                     {
                                         try
                                         {
                                         var getContactDetails = cc.CreateListService();
                                         var contactDetails = getContactDetails.GetContactsFromList(item.Id,null);

                                         foreach (var j in contactDetails.Results)
                                         {
                                            
                                             string message = getMessageDetails(txtMessage.Text.Trim(), j);
                                             string phone = getPhoneDetails(cmbFieldPhone.Text.Trim(), j);

                                             if (!string.IsNullOrEmpty(phone))
                                             {
                                                // Send SMS
                                                 string smsResult = SmsSender.SendSMS(phone, NexmoFromNumber, NexmoAPI, NexmoSecretKey, HttpUtility.UrlEncode(message));
                                                 count++;
                                             }
                                         }
                                         }
                                         catch (Exception ex)
                                         {
                                            // Logger.Write(ex);
                                             continue;
                                         }
                                     }
                                    if(count>0)
                                    {
                                             MessageBox.Show(CommonConstants.MandatoryFields.Success);
                                    }
                                    else
                                    {
                                            MessageBox.Show(CommonConstants.MandatoryFields.MSGNOTSEND);
                                    }
                           
                        this.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    finally
                    {
                        Cursor.Current = Cursors.Default;
                    }
                }
            }
        }