Free Support Forum - aspose.com

Option to access Gmail contacts group

Hi,


I want to send mail to a group of people present in my contacts list. This contact list is maintained on a Gmail account.

My query is:
Does Aspose.Email provide any option to access Gmail contact groups and respective email addresses??

Best Regards
Cornelius

Hi Cornelius,


Thanks for writing to Aspose.Emaill support team.

Aspose.Email provides facility to access the contacts and groups from a Gmail account. Please give a try to the following sample code which accesses the groups/contacts from a Gmail account and displays the email address of each contact.
// Create gmail client
GmailClient client = new GmailClient();
// Set Authentication credentials
client.Username = "user@gmail.com";
client.Password = "password";
client.AuthorizationType = GmailClientAuthorization.ClientLogin;
// login to the server
client.ClientLoginAuthenticate();

// Get contacts group collection
FeedEntryCollection groups = client.FetchAllGroups();

// Parse through all the contact groups
foreach (GmailContactGroup group in groups)
{
Console.WriteLine(group.Title);

// Get all the contacts from the group
FeedEntryCollection contacts = client.FetchContactsFromGroup(group);
// Parse all the contacts
foreach (GmailContact contact in contacts)
{
if(contact.PrimaryEmail != null)
Console.WriteLine("{0}: {1}", contact.Title, contact.PrimaryEmail.Address);
}
}

Please feel free to write us back if you have any other query in this regard.