For getting contacts from Gmail, first we need Google data DLLs, which can be downloaded from here.
Download the installer and install, this installer will install the Google data API.
After that add the reference of these DLLs into your project and include the namespace into your class.
- using Google.GData.Contacts;
- using Google.GData.Client;
- using Google.GData.Extensions;
- using Google.Contacts;
After that you need to create RequestSettings and ContactsRequest
So first we create the object of RequestSettings and pass that object to ContactsRequest as in the following:
- RequestSettings _requestSettings = new RequestSettings("applicationName", "GmailUserID", "GmailPassword");
- ContactsRequest _contactsRequest = new ContactsRequest(_requestSettings);
- Feed<Contact> ContactList = _contactsRequest.GetContacts();
The preceding method will return a list of contacts.
For demo purposes, I have created a aspx page that will ask for your Gmail userid and password and when you enter valid credentials, it displays all the friend's Email.
Code for aspx page:
- <form id="form1" runat="server">
- <div>
- <table>
- <tr>
- <td colspan="2">
- <asp:Label ID="LabelErrorMessage" runat="server" ForeColor="Red" Visible="false"></asp:Label>
- </td>
- </tr>
- <tr>
- <td>
- <strong>Enter userid: </strong>
- </td>
- <td>
- <asp:TextBox ID="TextBoxUserID" runat="server"></asp:TextBox>
- </td>
- </tr>
- <tr>
- <td>
- <strong>Enter Password: </strong>
- </td>
- <td>
- <asp:TextBox ID="TextBoxPassword" runat="server" TextMode="Password"></asp:TextBox>
- </td>
- </tr>
- <tr>
- <td>
- </td>
- <td>
- <asp:Button ID="ButtonImportContacts" runat="server" Text="Import Contacts" OnClick="ButtonImportContacts_Click" />
- </td>
- </tr>
- </table>
- </div>
- <div>
- <asp:Repeater ID="RepeaterContactsList" runat="server">
- <HeaderTemplate>
- <b>Friends EmailID</b>
- </HeaderTemplate>
- <ItemTemplate>
- <br />
- <%# DataBinder.Eval(Container.DataItem, "EmailID")%>
- </ItemTemplate>
- </asp:Repeater>
- </div>
- </form>
Code for .cs page
- using System;
- using System.Configuration;
- using System.Data;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.HtmlControls;
- using System.Web.UI.WebControls;
- using System.Collections.Generic;
- using Google.GData.Contacts;
- using Google.GData.Client;
- using Google.GData.Extensions;
- using Google.Contacts;
- public partial class _Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- public List<GmailContacts> ImportContacts(string applicationName, string userName, string userPassword)
- {
- List<GmailContacts> emailList = new List<GmailContacts>();
- RequestSettings _requestSettings = new RequestSettings(applicationName, userName, userPassword);
- _requestSettings.AutoPaging = true;
- ContactsRequest _contactsRequest = new ContactsRequest(_requestSettings);
- Feed<Contact> ContactList = _contactsRequest.GetContacts();
- try
- {
- LabelErrorMessage.Visible = false;
- foreach (Contact contact in ContactList.Entries)
- {
- foreach (EMail email in contact.Emails)
- {
- GmailContacts gc = new GmailContacts();
- gc.EmailID = email.Address;
- emailList.Add(gc);
- }
- }
- }
- catch (Exception ex)
- {
- LabelErrorMessage.Visible = true;
- LabelErrorMessage.Text = ex.Message;
- }
- return emailList;
- }
- protected void ButtonImportContacts_Click(object sender, EventArgs e)
- {
- List<GmailContacts> ImportList = new List<GmailContacts>();
- ImportList = ImportContacts("ImportContacts", TextBoxUserID.Text, TextBoxPassword.Text);
- RepeaterContactsList.DataSource = ImportList;
- RepeaterContactsList.DataBind();
- }
- }
- public class GmailContacts
- {
- private string _EmailID;
- public string EmailID
- {
- get
- {
- return _EmailID;
- }
- set
- {
- _EmailID = value;
- }
- }
- }
By this way you can easily import Gmail contacts.

Mr NghiaPosted Oct 27, 2017, 3:47 AM
Execution of authentication request returned unexpected result: 404. please help me ?
Priya SwaminathanPosted Apr 19, 2016, 5:30 AM
"Execution of authentication request returned unexpected result: 404" I am getting this error please help me
Nipesh JanghelPosted Dec 15, 2014, 11:47 AM
Hi all,http://www.google.com/m8/feeds/contacts/default/fullMovedPermanently changed to secure https://www.google.com/m8/feeds/contacts/default/fullMovedPermanently so downlod new dll file.. https://code.google.com/p/google-gdata/downloads/list
lakshmana poojaryPosted Sep 22, 2014, 9:12 AM
Hi%20Sir%2C%20I%20have%20tried%20this.%20But%20If%20i%20have%20given%20the%20right%20user%20name%20and%20password%20also%20%2C%20I%20am%20getting%20the%20error%20as%20Invalid%20credentials.%20Please%20help%20me%20out%2C%20if%20I%20have%20done%20anything%20wrong%20somewhere.!
nagababu sreeramPosted Jul 27, 2014, 2:38 AM
I am also getting this error..??Execution of request returned unexpected result: http://www.google.com/m8/feeds/contacts/default/fullMovedPermanently
Ajay mylaramPosted Jul 14, 2014, 2:00 AM
I am getting this error..??Execution of request returned unexpected result: http://www.google.com/m8/feeds/contacts/default/fullMovedPermanently
Nisha DwivediPosted Jul 21, 2013, 1:16 AM
nice article
Rasadul Alam RashedPosted Jul 10, 2013, 2:16 AM
Send E-mail using ASP.NET, C# The Microsoft .NET framework provides two namespaces, System.Net and System.Net.Sockets to send or receive data over the Internet. SMTP protocol is using for sending email from C#. C# use System.Net.Mail namespace for sending email. To send e-mail you need to configure SMTP server. If you don’t have any SMTP, you can use free SMTP server. You can also use your gmail account. The following C# source code shows how to send an email using SMTP server. Code is here : http://cybarlab.blogspot.com/2013/03/send-e-mail-using-c-sharp.html
Mahesh ChandPosted Jul 8, 2013, 10:34 AM
Nice. This should be published in ASP.NET section.
Pradip PandeyPosted Jul 8, 2013, 6:42 AM
Useful information and nicely explained.