How to create and update gmail group using Google-Contacts

605 views Asked by At

I am having the following criteria:-

1.Create gmail group using query execution in sql db. This query will filter contacts on the basis of region.

2.These contacts may or may not be different for each send request. It depends upon the users those who are active at the time of send.

3.I am able to send mail to group.

Main problem is related with how i can update group each time before sending mail to group members excluding inactive members.

Please let me know if you need more explanation.I will try my best.

UPDATE:

I had done the following code from a Console application:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Google.Contacts;
using Google.GData.Contacts;
using Google.GData.Client;
using Google.GData.Extensions;

namespace IMAPCommands
{
class Program
{

    static void Main(string[] args)
    {   GoogleContactService.InitializeService("mailid", "password");
        List<ContactDetail> test = GoogleContactService.GetContacts("System Group: My Contacts");
//Use break point here
            Console.ReadLine();
        }



public class GoogleContactService
    {
    #region Properties
    public static ContactsService GContactService = null;
    #endregion

    #region Methods

    public static void InitializeService(string username, string password)
    {
        GContactService = new ContactsService("Contact Infomation");
        GContactService.setUserCredentials(username, password);
    }

    public static List<ContactDetail> GetContacts(string GroupName = null)
    {

        List<ContactDetail> contactDetails = new List<ContactDetail>();
        ContactsQuery contactQuery = new ContactsQuery(ContactsQuery.CreateContactsUri("default"));
        contactQuery.NumberToRetrieve = 1000;

        if (!String.IsNullOrEmpty(GroupName))
        {
            GroupEntry ge = GetGroup(GroupName);
            if (ge != null)
                contactQuery.Group = ge.Id.AbsoluteUri;
        }
        else
        {
            string groupName = "";
            GroupEntry ge = GetGroup(groupName);
            if (ge != null)
                contactQuery.Group = ge.Id.AbsoluteUri;
        }

        ContactsFeed feed = GContactService.Query(contactQuery);
        foreach (ContactEntry entry in feed.Entries)
        {
            if (entry.Title.Text == "TechnicalBulletinName")
            {
                int test = entry.Emails.Count;
                ContactDetail contact = new ContactDetail
                {
                    Name = entry.Title.Text,
                    EmailAddress1 = entry.Emails.Count >= 1 ? entry.Emails[0].Address : "",
                    EmailAddress2 = entry.Emails.Count >= 2 ? entry.Emails[1].Address : "",
                    Phone1 = entry.Phonenumbers.Count >= 1 ? entry.Phonenumbers[0].Value : "",
                    Phone2 = entry.Phonenumbers.Count >= 2 ? entry.Phonenumbers[1].Value : "",
                    Address = entry.PostalAddresses.Count >= 1 ? entry.PostalAddresses[0].FormattedAddress : "",
                    Details = entry.Content.Content
                };

                contact.UserDefinedFields = new List<UDT>();
                foreach (var udt in entry.UserDefinedFields)
                {
                    contact.UserDefinedFields.Add(new UDT { Key = udt.Key, Value = udt.Value });
                }

                contactDetails.Add(contact);
            }
        }

        return contactDetails;
    }
    #endregion

    #region Helpers
    public static GroupEntry GetGroup(string GroupName)
    {
        GroupEntry groupEntry = null;
        GroupsQuery groupQuery = new GroupsQuery(GroupsQuery.CreateGroupsUri("default"));
        groupQuery.NumberToRetrieve = 100;
        GroupsFeed groupFeed = GContactService.Query(groupQuery);
        foreach (GroupEntry entry in groupFeed.Entries)
        {
            if (entry.Title.Text.Equals(GroupName, StringComparison.CurrentCultureIgnoreCase))
            {
                groupEntry = entry;
                break;
            }
        }
        return groupEntry;
    }
    #endregion
}

public class ContactDetail
{
    public string Name { get; set; }
    public string EmailAddress1 { get; set; }
    public string EmailAddress2 { get; set; }
    public string Phone1 { get; set; }
    public string Phone2 { get; set; }
    public string Address { get; set; }
    public string Details { get; set; }
    public string Pipe { get; set; }
    public string Relationship { get; set; }
    public string Status { get; set; }
    public List<UDT> UserDefinedFields { get; set; }
}
public class UDT
{
    public string Key { get; set; }
    public string Value { get; set; }
}
}

Still not able to get list of contacts which are member of group TechnicalBulletinName. I am only able to get emailID of this group not members of the group.

0

There are 0 answers