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(); }
protected void btnCreateCampaign_Click(object sender, EventArgs e) { try { string _accessToken = GetListService();// OAuth.GetAccessTokenByCode(HttpContext.Current, Request.QueryString["code"].ToString()); string _apiKey = ConfigurationManager.AppSettings["APIKey"]; IUserServiceContext userServiceContext = new UserServiceContext(_accessToken, _apiKey); ConstantContactFactory _constantContactFactory = new ConstantContactFactory(userServiceContext); _emailCampaignService = _constantContactFactory.CreateEmailCampaignService(); _emailCampaginScheduleService = _constantContactFactory.CreateCampaignScheduleService(); // EmailCampaign campaign = CreateCampaignFromInputs(); EmailCampaign campaign = CreateCampaignFromInputs(); var savedCampaign = _emailCampaignService.AddCampaign(campaign); if (savedCampaign != null) { //campaign was saved, but need to schedule it, if the case Schedule schedule = null; { schedule = new Schedule() { ScheduledDate = Convert.ToDateTime(DateTime.Now.AddMinutes(1).ToShortTimeString().Trim()).ToUniversalTime() }; } Schedule savedSchedule = _emailCampaginScheduleService.AddSchedule(savedCampaign.Id, schedule); } } catch (Exception ex) { } }
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(); }
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)); } }
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); }
protected void btnAddLead_Click(object sender, EventArgs e) { LeadData lead = new LeadData(); lead.BusinessName = txtBusinessName.Text; lead.ComplianceAgent = txtComplianceAgent.Text; lead.ContactName = txtContactName.Text; lead.DOTNo = txtDoT.Text; lead.Email = txtEmail.Text; lead.Notes = txtNotes.Text; lead.PhoneNoForContact = txtBestPhone.Text; lead.SalesPersonID = Convert.ToInt32(Request.Cookies["UserID"].Value); lead.ServiceDiscussed = txtServiceDiscussed.Text; lead.TimeLine = txtTimeLine.Text; bool isLeadAdded = leadHelper.AddLead(lead); IUserServiceContext userServiceContext = new UserServiceContext(_accessToken, _apiKey); ConstantContactFactory serviceFactory = new ConstantContactFactory(userServiceContext); //List<string> lists = new List<string>() { "1236366064" }; List <string> lists = new List <string>(); string[] emailid = hdnEmailID.Value.Split(','); foreach (string item in emailid) { if (!String.IsNullOrEmpty(item)) { lists.Add(item); } } List <ContactList> contactLists = new List <ContactList>(); foreach (string list in lists) { ContactList contactList = new ContactList() { Id = list }; contactLists.Add(contactList); } if (isLeadAdded) { int leadID = Convert.ToInt32(Request.QueryString["LeadID"]); DailyLeadEntity dailyLead = dailyLeadHelper.GetLeadRecordsByLeadID(leadID); var contactService = serviceFactory.CreateContactService(); string physicalCity = ""; try { physicalCity = dailyLead.PhysicalAddress.Split(',')[1].Split(null)[1]; } catch { } Address address = new Address(); try { address = new Address() { AddressType = "BUSINESS", City = toString(physicalCity), CountryCode = "US", Line1 = toString(dailyLead.MailingAddress.Substring(0, 40)), Line2 = toString(dailyLead.MailingAddress.Substring(0, 40)), PostalCode = toString(dailyLead.ZipCode), StateCode = toString("ID"), }; } catch { address = new Address() { AddressType = "BUSINESS" }; } try { if (dailyLead != null) { Contact contact = new Contact() { Addresses = new List <Address> { address }, Lists = contactLists, CellPhone = dailyLead.PhoneNo, CompanyName = toString(dailyLead.LegalName), Confirmed = true, EmailAddresses = new List <EmailAddress> { new EmailAddress(toString(txtEmail.Text)) }, Fax = dailyLead.PhoneNo, FirstName = txtContactName.Text, HomePhone = txtBestPhone.Text, JobTitle = "Purcell Compliance Lead", LastName = toString(""), PrefixName = "Mr.", WorkPhone = dailyLead.PhoneNo }; contactService.AddContact(contact, false); } else { Contact contact = new Contact() { Addresses = new List <Address> { address }, Lists = contactLists, CellPhone = txtBestPhone.Text, CompanyName = toString(txtBusinessName.Text), Confirmed = true, EmailAddresses = new List <EmailAddress> { new EmailAddress(toString(txtEmail.Text)) }, Fax = txtBestPhone.Text, FirstName = txtContactName.Text, HomePhone = txtBestPhone.Text, JobTitle = "Purcell Compliance Lead", LastName = toString(""), PrefixName = "Mr.", WorkPhone = txtBestPhone.Text }; contactService.AddContact(contact, false); } Response.Write("<script>alert('Lead added Successfully.');</script>"); resetControls(); } catch { //Response.Write("<script>alert('" + ex.Message + "');</script>"); } } else { Response.Write("<script>alert('Some error occured.');</script>"); } }
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; } } } }
/// <summary> /// Bind Campaign in dropdown /// </summary> public void LoadCampaign() { try { ApiKey = ConstantContactAPI; AccessToken = ConstantContactToken; IUserServiceContext userServiceContext = new UserServiceContext(AccessToken, ApiKey); var cc = new ConstantContactFactory(userServiceContext); var emailCampignService = cc.CreateEmailCampaignService(); ResultSet<EmailCampaign> listsAll = emailCampignService.GetCampaigns(null, null, null); ResultSet<EmailCampaign> filteredList = new ResultSet<EmailCampaign>() ; List<ConstantContactList> mailChimpList = new List<ConstantContactList>(); if (listsAll != null && listsAll.Results.Count > 0) { filteredList.Results = listsAll.Results.Where(p => p.Status.Equals(CampaignStatus.DRAFT)).ToList(); if (!chkDraft.Checked) { var newList = filteredList.Results.ToList(); newList.RemoveAll(p => p.Status == CampaignStatus.DRAFT); filteredList.Results = newList; } else { filteredList.Results = listsAll.Results.Where(p => p.Status == CampaignStatus.DRAFT).ToList(); } if (!chkSchedule.Checked) { filteredList.Results.ToList().RemoveAll(p => p.Status == CampaignStatus.SCHEDULED); } else { var newList = filteredList.Results.ToList(); newList.RemoveAll(p => p.Status == CampaignStatus.SCHEDULED); filteredList.Results = newList; filteredList.Results = filteredList.Results.Concat(listsAll.Results.Where(p => p.Status == CampaignStatus.SCHEDULED)).ToList(); } if (!chkSent.Checked) { var newList = filteredList.Results.ToList(); newList.RemoveAll(p => p.Status == CampaignStatus.SENT); filteredList.Results = newList; } else { if (filteredList.Results != null) { var newList = filteredList.Results.ToList(); newList.RemoveAll(p => p.Status == CampaignStatus.SENT); filteredList.Results = newList; filteredList.Results = filteredList.Results.Concat(listsAll.Results.Where(p => p.Status == CampaignStatus.SENT)).ToList(); } } cmbCampaign.DataSource = null; cmbCampaign.Items.Clear(); mailChimpList.Add(new ConstantContactList("0", CommonConstants.MandatoryFields.SelectCampaign)); foreach (var list in filteredList.Results.OrderBy(p=>p.Name)) { mailChimpList.Add(new ConstantContactList(list.Id.ToString(), list.Name+" "+'(' + list.Status + ')')); } cmbCampaign.DisplayMember = "Name"; cmbCampaign.ValueMember = "Id"; cmbCampaign.DataSource = mailChimpList; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void frmContact_Load(object sender, EventArgs e) { try { string state = "ok"; _accessToken = OAuth.AuthenticateFromWinProgram(ref state); if (string.IsNullOrEmpty(_accessToken)) { Application.Exit(); } //initialize ConstantContact member IUserServiceContext userServiceContext = new UserServiceContext(_accessToken, _apiKey); _constantContactFactory = new ConstantContactFactory(userServiceContext); } catch (OAuth2Exception oauthEx) { MessageBox.Show(string.Format("Authentication failure: {0}", oauthEx.Message), "Warning"); } toolTipClose.SetToolTip(lblClose, "Close"); lblErrorMsg.Visible = false; #region Populate list of countries var countries = new List <RegionInfo>(); CultureInfo[] cinfo = CultureInfo.GetCultures(CultureTypes.SpecificCultures); foreach (CultureInfo cul in cinfo) { var country = new RegionInfo(cul.LCID); if (country != null && !countries.Contains(country)) { countries.Add(country); } } countries = countries.OrderBy(c => c.EnglishName).ToList(); cbCountry.Items.Add(new CountryInfo(string.Empty, string.Empty)); var US = countries.Where(c => c.EnglishName.Equals("United States")).FirstOrDefault(); var Canada = countries.Where(c => c.EnglishName.Equals("Canada")).FirstOrDefault(); if (US != null) { countries.Remove(US); } if (Canada != null) { countries.Remove(Canada); } var lstCountries = countries.Select(c => new CountryInfo(c.EnglishName, c.TwoLetterISORegionName)).ToArray(); if (US != null) { cbCountry.Items.Add(new CountryInfo(US.EnglishName, US.TwoLetterISORegionName)); } if (Canada != null) { cbCountry.Items.Add(new CountryInfo(Canada.EnglishName, Canada.TwoLetterISORegionName)); } cbCountry.Items.AddRange(lstCountries); cbCountry.ValueMember = "TwoLetterCountryName"; cbCountry.DisplayMember = "Name"; #endregion Populate list of countries }