working on it ...

Filters

Explore Public Snippets

Sort by

Found 700 snippets matching: contacts

    public by cghersi @ MailUp API DEV  206839  8  6  1

    MailUp REST API - How to subscribe to a particular list several contacts with the "Confirmed Optin" Procedure

    This snippet takes advantage of the MailUp .NET SDK to setup the secure communication towards the server through OAuth2 two leg authentication. You can start digging into the MailUP API world by reading this content: http://help.mailup.com/display/mailupapi/REST+API An instance of MailUpClient class is able to manage one user at a time. A MailU
    public static void SubcribeRecipientsWithDoubleOptin(string clientID, string clientSecret, string username, string password)
    {
        // 1) Setup the MailUp Client:
        MailUpClient client = new MailUpClient(clientID, clientSecret);
        try
        {
            client.RetrieveAccessToken(username, password);
        }
        catch (MailUpException ex)
        {
            Console.WriteLine("Unable to access the service due to " + ex.Message);
            return;
        }
    
        // 2) Subscribe recipients:
        int idList = 1;
        List<ConsoleRecipientItem> recipients = new List<ConsoleRecipientItem>();
        ConsoleRecipientItem recipient1 = new ConsoleRecipientItem()
        {
            Email = "test1@mailup.com",
            Name = "First New Recipient" + DateTime.Now.ToFileTimeUtc(),
            MobileNumber = "3331234567",
            MobilePrefix = "39",
            Fields = new List<ConsoleRecipientDynamicFieldItem>()
            {
                new ConsoleRecipientDynamicFieldItem() { Id = 1, Value = "Name1_" + DateTime.Now.ToFileTimeUtc() },
                new ConsoleRecipientDynamicFieldItem() { Id = 2, Value = "LastName1_" + DateTime.Now.ToFileTimeUtc() }
                //here you can add all the fields you want to add...
            }
        };
        ConsoleRecipientItem recipient2 = new ConsoleRecipientItem()
        {
            Email = "test2@mailup.com",
            Name = "Second New Recipient" + DateTime.Now.ToFileTimeUtc(),
            MobileNumber = "3337654321",
            MobilePrefix = "39",
            Fields = new List<ConsoleRecipientDynamicFieldItem>()
            {
                new ConsoleRecipientDynamicFieldItem() { Id = 1, Value = "Name2_" + DateTime.Now.ToFileTimeUtc() },
                new ConsoleRecipientDynamicFieldItem() { Id = 2, Value = "LastName2_" + DateTime.Now.ToFileTimeUtc() }
                //here you can add all the fields you want to add...
            }
        };
        recipients.Add(recipient1);
        recipients.Add(recipient2);
        int subscriptionResult = 0;
        try
        {
            subscriptionResult = client.AddRecipientsToList(idList, recipients, true);
        }
        catch (Exception ex)
        {
            Console.WriteLine("Cannot perform the operation due to " + ex.Message);
            return;
        }
    
        // 2.1) wait for the end of import task:
        if (subscriptionResult > 0)
        {
            Console.WriteLine("Recipients Import started; import ID:" + subscriptionResult);
    
            //optionally we can check the import status:
            bool completed = false;
            do
            {
                ConsoleImportStatus importStatus = client.CheckImportStatus(subscriptionResult);
                if (importStatus == null)
                {
                    Console.WriteLine("Cannot check the import status for import task #" + subscriptionResult);
                    return;
                }
                completed = importStatus.Completed;
            } while (!completed);
            Console.WriteLine("Recipients Added!");
        }
        else
        {
            Console.WriteLine("An error occurred while adding the recipients.");
            return;
        }
    
        // 3) Retrieve the sendingID of the confirmation email related to the previous task:
        int sendingID = -1;
        try
        {
            sendingID = client.GetSendingIDForImport(subscriptionResult);
        }
        catch (Exception ex)
        {
            Console.WriteLine("Cannot retrieve sending ID due to " + ex.Message);
            return;
        }
        if (sendingID <= 0)
        {
            Console.WriteLine("Cannot retrieve sending ID.");
            return;
        }
    
        // 4) Send the confirmation email:
        EmailSendingItem sendingResult = null;
        try
        {
            sendingResult = client.SendEmailMessage(sendingID);
        }
        catch (Exception ex)
        {
            Console.WriteLine("Cannot send email due to " + ex.Message);
            return;
        }
        if (sendingResult == null)
            Console.WriteLine("Cannot send confirmation email.");
        else
            Console.WriteLine("Confirmation email sent!");
    }
                

    public by cghersi  5821  1  8  3

    How to retrieve GMail contacts via API, using OAuth2 token and not username/password credentials

    This class takes charge of the interaction with Google Contacts API, authenticating with an AccessToken authorization flow. In this way the final user should type the credentials in the Google form and not in your form. The "token" parameter of GetContacts() method is the one sent by Google to the callback url specified in the static constant "s_
    using System;
    using System.Linq;
    using System.Collections.Generic;
    using Google.Contacts;
    using Google.GData.Contacts;
    using Google.GData.Client;
    using Google.GData.Extensions;
    
    namespace Contact.Utils
    {
      /// <summary>
      /// Summary description for GmailHelper
      /// </summary>
      public class GmailHelper
      {
        private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
    
        private static fastJSON.JSON jsonUtils = EntityUtils.InitJSONUtils();
    
        private static readonly string APP_NAME = "my app name";
        private static readonly string s_ClientId = "client id given by Google";
        private static readonly string s_ClientSecret = "secret given by Google;
        private static readonly string s_accessTokenUrl = "https://accounts.google.com/o/oauth2/token";
        private static readonly string s_redirUri = WebConfig.Current.PublicPath + "User/GmailCallback";
    
        #region PUBLIC API
        //////////////////////////////////////////////////////////////////////////////////////////////////////
    
        public static string GetRedirUriForContacts()
        {
          return string.Format("https://accounts.google.com/o/oauth2/auth?scope=https://www.google.com/m8/feeds&redirect_uri={0}&response_type=code&client_id={1}",
            s_redirUri, s_ClientId);
        }
    
        public static List<SimpleContact> GetContacts(string token)
        {
          List<SimpleContact> results = new List<SimpleContact>();
    
          //exchange the code for a token:
          string postData = string.Format("code={0}&client_id={1}&client_secret={2}&redirect_uri={3}&grant_type=authorization_code",
            token, s_ClientId, s_ClientSecret, s_redirUri);
          string accessTokenResp = Utilities.SendHttpRequest(s_accessTokenUrl, postData, true);
          if (string.IsNullOrEmpty(accessTokenResp))
            return results;
    
          AccessTokenStruct parsedJson = null;
          try
          {
            parsedJson = jsonUtils.ToObject<AccessTokenStruct>(accessTokenResp); 
          }
          catch (Exception e)
          {
            log.ErrorFormat("Cannot deserialize access token response: '{0}' due to {1}", accessTokenResp, e.Message);
            return results;
          }
          if (parsedJson == null)
            return results;
    
          //ask for contacts:
          RequestSettings settings = new RequestSettings(APP_NAME, parsedJson.access_token); 
          settings.AutoPaging = true;
          ContactsRequest cr = new ContactsRequest(settings);
          Feed<Contact> contactsFeed = cr.GetContacts();
          IEnumerable<Contact> contacts = null;
          if (contactsFeed != null)
            contacts = contactsFeed.Entries;
          if (contacts == null)
            return results;
    
          try
          {
            foreach (SimpleContact c in contacts)
            {
              if (c.PrimaryEmail == null)
                continue;
              string preferredEmail = c.PrimaryEmail.Address;
              if (string.IsNullOrEmpty(preferredEmail))
                continue;
              string[] otherEmails = null;
              if (c.Emails != null)
                otherEmails = c.Emails.Select(e => e.Address).ToArray();
              S2CContact contact = new S2CContact((c.Name == null ? "" : c.Name.FullName), 
                                                  preferredEmail, otherEmails);
              results.Add(contact);
            }
          }
          catch (Exception e)
          {
            log.ErrorFormat("Cannot retrieve contacts due to {0}", e.Message);
            return results;
          }
    
          return results;
        }
    
        #endregion
        //////////////////////////////////////////////////////////////////////////////////////////////////////
      }
    
      public class AccessTokenStruct
      {
        public string access_token { get; set; }
        public int expires_in { get; set; }
        public string token_type { get; set; }
    
        public AccessTokenStruct() { }
      }
    
      public class SimpleContact
      {
        public string PreferredEmail { get; set; }
        public string Name { get; set; }
        public string[] Emails { get; set; }
    
        public SimpleContact(string name, string preferredEmail, string[] emails = null)
        {
          Name = name;
          PreferredEmail = preferredEmail;
          if (emails == null)
            Emails = new string[] { preferredEmail };
          else
          {
            List<string> allEmails = new List<string>(emails);
            allEmails.Add(preferredEmail);
            Emails = allEmails.Distinct().ToArray();
          }
        }
    
        public override string ToString()
        {
          if (string.IsNullOrEmpty(Name))
            return PreferredEmail;
          else
            return string.Format("{0} [{1}]", Name, PreferredEmail);
        }
      }
    
    }            

    public by cghersi @ MailUp API DEV  1311  26  7  0

    MailUp REST API - How to subscribe to a particular list several contacts with some information like email, mobile number, etc.

    This snippet takes advantage of the MailUp .NET SDK to setup the secure communication towards the server through OAuth2 two leg authentication. You can start digging into the MailUP API world by reading this content: http://help.mailup.com/display/mailupapi/REST+API An instance of MailUpClient class is able to manage one user at a time. A MailU
    public static void SubcribeRecipients(string clientID, string clientSecret, string username, string password)
    {
        // 1) Setup the MailUp Client:
        MailUpClient client = new MailUpClient(clientID, clientSecret);
        try
        {
            client.RetrieveAccessToken(username, password);
        }
        catch (MailUpException ex)
        {
            Console.WriteLine("Unable to access the service due to " + ex.Message);
            return;
        }
    
        // 2) Prepare the input:
        int idList = 1;
        List<ConsoleRecipientItem> recipients = new List<ConsoleRecipientItem>();
        ConsoleRecipientItem recipient1 = new ConsoleRecipientItem()
        {
            Email = "test1@mailup.com",
            Name = "First New Recipient" + DateTime.Now.ToFileTimeUtc(),
            MobileNumber = "3331234567",
            MobilePrefix = "39",
            Fields = new List<ConsoleRecipientDynamicFieldItem>()
            {
                new ConsoleRecipientDynamicFieldItem() { Id = 1, Value = "Name1_" + DateTime.Now.ToFileTimeUtc() },
                new ConsoleRecipientDynamicFieldItem() { Id = 2, Value = "LastName1_" + DateTime.Now.ToFileTimeUtc() }
                //here you can add all the fields you want to add...
            }
        };
        ConsoleRecipientItem recipient2 = new ConsoleRecipientItem()
        {
            Email = "test2@mailup.com",
            Name = "Second New Recipient" + DateTime.Now.ToFileTimeUtc(),
            MobileNumber = "3337654321",
            MobilePrefix = "39",
            Fields = new List<ConsoleRecipientDynamicFieldItem>()
            {
                new ConsoleRecipientDynamicFieldItem() { Id = 1, Value = "Name2_" + DateTime.Now.ToFileTimeUtc() },
                new ConsoleRecipientDynamicFieldItem() { Id = 2, Value = "LastName2_" + DateTime.Now.ToFileTimeUtc() }
                //here you can add all the fields you want to add...
            }
        };
        recipients.Add(recipient1);
        recipients.Add(recipient2);
    
        // 3) Invoke the web method:
        int result = 0;
        try
        {
            result = client.AddRecipientsToList(idList, recipients);
        }
        catch (Exception ex)
        {
            Console.WriteLine("Cannot perform the operation due to " + ex.Message);
            return;
        }
    
        // 4) Print results:
        if (result > 0)
        {
            Console.WriteLine("Recipients Import started; import ID:" + result);
    
            //optionally we can check the import status:
            bool completed = false;
            do
            {
                ConsoleImportStatus importStatus = client.CheckImportStatus(result);
                if (importStatus == null)
                {
                    Console.WriteLine("Cannot check the import status for import task #" + result);
                    return;
                }
                completed = importStatus.Completed;
            } while (!completed);
            Console.WriteLine("Recipients Added!");
        }
        else
            Console.WriteLine("An error occurred while adding the recipients.");
    }
    

    public by p.kontalis  1960  2  5  0

    Contacts Export from VTiger to Google Contacts

    SELECT 
    REPLACE (REPLACE (accountname, '"', '_'), ',', '_') AS 'Name',
    REPLACE (REPLACE (accountname, '"', '_'), ',', '_') AS 'Given Name',
    '' AS 'Additional Name',
    '' AS 'Family Name',
    '' AS 'Yomi Name',
    '' AS 'Given Name Yomi',
    '' AS 'Additional Name Yomi',
    '' AS 'Family Name Yomi',
    '' AS 'Name Prefix',
    '' AS 'Name Suffix',
    '' AS 'Initials',
    '' AS 'Nickname',
    '' AS 'Short Name',
    '' AS 'Maiden Name',
    '' AS 'Birthday',
    '' AS 'Gender',
    '' AS 'Location',
    '' AS 'Billing Information',
    '' AS 'Directory Server',
    '' AS 'Mileage',
    '' AS 'Occupation',
    '' AS 'Hobby',
    '' AS 'Sensitivity',
    '' AS 'Priority',
    '' AS 'Subject',
    '' AS 'Notes',
    '* My Contacts' AS 'Group Membership',
    '* Work' AS 'E-mail 1 - Type',
    REPLACE (REPLACE (email1, '"', '_'), ',', '_') AS 'E-mail 1 - Value',
    'Εργασία 2' AS 'E-mail 2 - Type',
    REPLACE (REPLACE (email2, '"', '_'), ',', '_') AS 'E-mail 2 - Value',
    'Εργασία 2' AS 'Phone 1 - Type',
    REPLACE (REPLACE (phone, '"', '_'), ',', '_') AS 'Phone 1 - Value',
    'Work' AS 'Phone 2 - Type',
    REPLACE (REPLACE (otherphone, '"', '_'), ',', '_') AS 'Phone 2 - Value',
    'Fax' AS 'Phone3 - Type',
    REPLACE (REPLACE (fax, '"', '_'), ',', '_') AS 'Phone 3 - Value',
    'Home' AS 'Address 1 - Type',
    CONCAT('"',bill_street,'\n',bill_city,bill_state,' ',bill_pobox,'\n',bill_country,'"') AS 'Address 1 - Formatted',
    REPLACE (REPLACE (bill_street, '"', '_'), ',', '_') AS 'Address 1 - Street',
    REPLACE (REPLACE (bill_city, '"', '_'), ',', '_') AS 'Address 1 - City',
    '' AS 'Address 1 - PO Box',
    REPLACE (REPLACE (bill_state, '"', '_'), ',', '_') AS 'Address 1 - Region',
    REPLACE (REPLACE (bill_pobox, '"', '_'), ',', '_') AS 'Address 1 - Postal Code',
    REPLACE (REPLACE (bill_country, '"', '_'), ',', '_') AS 'Address 1 - Country',
    '' AS 'Address 1 - Extended Address',
    'Home Page' AS 'Website 1 - Type',
    REPLACE (REPLACE (website, '"', '_'), ',', '_') AS 'Website 1 - Value'
    FROM vtigercrm600.vtiger_account
    LEFT JOIN vtigercrm600.vtiger_accountbillads
    ON vtiger_account.accountid = vtiger_accountbillads.accountaddressid;
    # NOTE: - After the execution click on export button and save it as csv
    # NOTE: The " and , have been replaced by _    
    # NOTE: If you want to use this snippet, consider to change the "vtigercrm600" with your database name. ;)
    

    public by Zenitram.PRO  5009  15  6  1

    Linear search in an Array.

    Finding that Special Someone Let's say we're looking for someone in our address book with a specific last name. We can do this with a technique for searching arrays called "linear search". With it, we use a loop to check through all of the items in the array one-by-one until we see the item that we want. We can apply linear search to print
    var bob = {
        firstName: "Bob",
        lastName: "Jones",
        phoneNumber: "(650) 777-7777",
        email: "bob.jones@example.com"
    };
    
    var mary = {
        firstName: "Mary",
        lastName: "Johnson",
        phoneNumber: "(650) 888-8888",
        email: "mary.johnson@example.com"
    };
    
    var contacts = [bob, mary];
    
    function printPerson(person) {
        console.log(person.firstName + " " + person.lastName);
    }
    
    function list() {
    	var contactsLength = contacts.length;
    	for (var i = 0; i < contactsLength; i++) {
    		printPerson(contacts[i]);
    	}
    }
    
    /*Create a search function
    then call it passing "Jones"*/
    function search(lastName)
    {
        contactsLength = contacts.length;
    	for (var i = 0; i < contactsLength; i++) 
    	{
    	    if (lastName === contacts[i]["lastName"])
    	    {
    	        printPerson(contacts[i]);
    	    }
    	}
    }
    
    search("Jones");                                    

    public by Zenitram.PRO  2309  21  5  3

    Adding element in an Array.

    We Made a Friend! We have our address book in the contacts array, but what if we make a new friend and want to add them as well? Objects, just like other types of data, can be put into arrays with a array[position] = object statement. To append something to the end of the array, you need to put it in the position one after the last item. S
    var bob = {
        firstName: "Bob",
        lastName: "Jones",
        phoneNumber: "(650) 777-7777",
        email: "bob.jones@example.com"
    };
    
    var mary = {
        firstName: "Mary",
        lastName: "Johnson",
        phoneNumber: "(650) 888-8888",
        email: "mary.johnson@example.com"
    };
    
    var contacts = [bob, mary];
    
    function printPerson(person) {
        console.log(person.firstName + " " + person.lastName);
    }
    
    function list() {
    	var contactsLength = contacts.length;
    	for (var i = 0; i < contactsLength; i++) {
    		printPerson(contacts[i]);
    	}
    }
    
    /*Create a search function
    then call it passing "Jones"*/
    function search(lastName)
    {
        contactsLength = contacts.length;
    	for (var i = 0; i < contactsLength; i++) 
    	{
    	    if (lastName === contacts[i]["lastName"])
    	    {
    	        printPerson(contacts[i]);
    	    }
    	}
    }
    
    function add(firstName, lastName, email, phoneNumber)
    {
        contacts[contacts.length] = {
        firstName: firstName,
        lastName: lastName,
        phoneNumber: phoneNumber,
        email: email
        };
    }
    
    add("paul", "martinez", "paul.martinez@examle.com", "+63 987 654 3210");
    list();
                                        

    public by msdn  151400  0  6  0

    CreateContactStore: Creates a contact store and add contacts.

    Creates a contact store and add contacts.
    using System;
    using System.Collections.Generic;
    using Windows.Phone.PersonalInformation;
    
    /// <summary>
    /// Creates a contact store and add contacts.
    /// </summary>
    public static async void CreateContactStore()
    {
        ContactStore contactStore = await ContactStore.CreateOrOpenAsync(
                        ContactStoreSystemAccessMode.ReadWrite,
                        ContactStoreApplicationAccessMode.ReadOnly);
    
        foreach (SampleContact sampleContact in SampleContact.CreateSampleContacts())
        {
            StoredContact contact = new StoredContact(contactStore);
            IDictionary<string, object> props = await contact.GetPropertiesAsync();
    
            if (!string.IsNullOrEmpty(sampleContact.FirstName))
            {
                props.Add(KnownContactProperties.GivenName, sampleContact.FirstName);
            }
    
            if (!string.IsNullOrEmpty(sampleContact.LastName))
            {
                props.Add(KnownContactProperties.FamilyName, sampleContact.LastName);
            }
    
            if (!string.IsNullOrEmpty(sampleContact.HomeEmail))
            {
                props.Add(KnownContactProperties.Email, sampleContact.HomeEmail);
            }
    
            if (!string.IsNullOrEmpty(sampleContact.WorkEmail))
            {
                props.Add(KnownContactProperties.WorkEmail, sampleContact.WorkEmail);
            }
    
            if (!string.IsNullOrEmpty(sampleContact.HomePhone))
            {
                props.Add(KnownContactProperties.Telephone, sampleContact.HomePhone);
            }
    
            if (!string.IsNullOrEmpty(sampleContact.WorkPhone))
            {
                props.Add(KnownContactProperties.CompanyTelephone, sampleContact.WorkPhone);
            }
    
            if (!string.IsNullOrEmpty(sampleContact.MobilePhone))
            {
                props.Add(KnownContactProperties.MobileTelephone, sampleContact.MobilePhone);
            }
    
            await contact.SaveAsync();
        }
    }

    public by msdn  1487  0  6  0

    ExportContacts: Export all contacts into the CSV file from Office 365 Exchange Online.

    Export all contacts into the CSV file from Office 365 Exchange Online.
    using System;
    using System.Collections.Generic;
    using Microsoft.Exchange.WebServices.Data;
    using System.Net;
    using System.Net.Security;
    using System.Security.Cryptography.X509Certificates;
    using System.IO;
    
    /// <summary>
    /// Export all contacts into the CSV file from Office 365 Exchange Online.
    /// </summary>
    private static void ExportContacts(ExchangeService service)
    {
        // Get the properties we need to write.
        PropertySet propertySet = new PropertySet();
        Dictionary<PropertyDefinitionBase, String> schemaList = 
            ContactsHelper.GetSchemaList();
        propertySet.AddRange(schemaList.Keys);
    
        List<Item> results = GetItems(service, null, WellKnownFolderName.Contacts, 
            propertySet);
        String path = GetFolderPath();
        String filePath = Path.Combine(path, "contacts.csv");
    
        using (StreamWriter writer = new StreamWriter(filePath))
        {
            Boolean firstCell = true;
    
            // Write the head title
            foreach (PropertyDefinitionBase head in schemaList.Keys)
            {
                if (!firstCell)
                {
                    writer.Write(",");
                }
                else
                {
                    firstCell = false;
                }
    
                writer.Write("\"{0}\"",schemaList[head]);
            }
            writer.WriteLine();
            firstCell = true;
    
            // Write the contact.
            foreach (Item item in results)
            {
                Contact contact = item as Contact;
    
                foreach (PropertyDefinitionBase proerty in schemaList.Keys)
                {
                    if (!firstCell)
                    {
                        writer.Write(",");
                    }
                    else
                    {
                        firstCell = false;
                    }
    
                    ContactsHelper.WriteContacts(writer, proerty, contact);
                }
    
                writer.WriteLine();
                firstCell = true;
            }
        }
    
        Console.WriteLine();
        Console.WriteLine("Export the contacts to the file:{0}",filePath); 
    }

    public by msdn  1314  0  6  0

    GetContactsByBirthday: This method gets the contacts that have the Birthday property definition in the special folder.

    This method gets the contacts that have the Birthday property definition in the special folder.
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Exchange.WebServices.Data;
    using System.IO;
    using System.Data;
    using System.Globalization;
    using System.Collections.ObjectModel;
    
    /// <summary>
    /// This method gets the contacts that have the Birthday property definition in the 
    /// special folder.
    /// </summary>
    public static List<Contact> GetContactsByBirthday(Folder contactsFolder, String name)
    {
        if (contactsFolder == null)
        {
            return null;
        }
    
        return GetContacts(contactsFolder, name, ContactSchema.Birthday);
    }

    public by msdn  1224  0  6  0

    GetContactsByBirthdayAndAnniversary: This method gets the contacts that have the Birthday and WeddingAnniversary property definition in the special folder.

    This method gets the contacts that have the Birthday and WeddingAnniversary property definition in the special folder.
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Exchange.WebServices.Data;
    using System.IO;
    using System.Data;
    using System.Globalization;
    using System.Collections.ObjectModel;
    
    /// <summary>
    /// This method gets the contacts that have the Birthday and WeddingAnniversary property   
    /// definition in the special folder.
    /// </summary>
    public static List<Contact> GetContactsByBirthdayAndAnniversary(Folder contactsFolder, String name)
    {
        if (contactsFolder == null)
        {
            return null;
        }
    
        return GetContacts(contactsFolder, name, ContactSchema.Birthday, ContactSchema.WeddingAnniversary);
    }
    • Public Snippets
    • Channels Snippets