Here is an blog to show how we can import gmail
data(email id from gmail) in asp.net by gmail id and password.
Step 1:
Download Google_Data_API_Setup_2.1.0.0.msi and install to your machine
from https://code.google.com/p/google-gdata/downloads/list
Step 2: Create a WebApplication and follow the code.
.aspx Page.
<%@
Page Language="C#"
AutoEventWireup="true"
CodeFile="import_gmail.aspx.cs"
Inherits="import_gmail"
%>
<!DOCTYPE
html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml">
<head
id="Head1"
runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 100%;
}
</style>
</head>
<body>
<form id="form1"
runat="server">
<div style="height:
100px; background-color:
#808080">
</div>
<div align="center">
<table
class="style1">
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
Enter
your Gmail id</td>
<td>
<asp:TextBox
ID="txt_email"
runat="server"
Width="250px"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1"
runat="server"
ControlToValidate="txt_email"
ErrorMessage="*"></asp:RequiredFieldValidator>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
Enter
your Gmail Password</td>
<td>
<asp:TextBox
ID="txtpass"
runat="server"
TextMode="Password"
Width="250px"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator2"
runat="server"
ControlToValidate="txtpass"
ErrorMessage="*"></asp:RequiredFieldValidator>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td
align="right">
<asp:Button
ID="Button1"
runat="server"
onclick="Button1_Click"
Text="Get List"
/>
</td>
<td>
<asp:Label
ID="lbl_email_count"
runat="server"
Text="Label"></asp:Label>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
<asp:GridView
ID="GV_List"
runat="server"
EnableModelValidation="True"
PageSize="25"
AutoGenerateColumns="False">
<Columns>
<asp:BoundField
DataField="emailid"
HeaderText="Email List"
/>
</Columns>
</asp:GridView>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Step 3: Add Referance to four dll from C:\Program Files\Google\Google
Data API SDK\Redist to your application.
Google.GData.Apps.dll
Google.GData.Client.dll
Google.GData.Contacts.dll
Google.GData.Extensions.dll
Step 4: Follow .CS code..
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
Google.GData.Contacts;
using
Google.GData.Client;
using
Google.GData.Extensions;
using
Google.Contacts;
using
System.Data;
using
System.Data.SqlClient;
public
partial class
import_gmail : System.Web.UI.Page
{
protected void Page_Load(object
sender, EventArgs e)
{
}
public DataSet GetGmailContacts(string
p_name, string e_id,
string psw)
{
DataSet ds =
new DataSet();
DataTable dt =
new DataTable();
DataColumn dc =
new DataColumn();
dc.DataType =
Type.GetType("System.String");
dc.ColumnName =
"emailid";
dt.Columns.Add(dc);
try
{
RequestSettings
rs = new RequestSettings(p_name, e_id, psw);
rs.AutoPaging =
true;
ContactsRequest
cr = new ContactsRequest(rs);
Feed<Contact> f =
cr.GetContacts();
foreach (Contact t in
f.Entries)
{
foreach (EMail email in
t.Emails)
{
DataRow
dr1 = dt.NewRow();
dr1["emailid"] = email.Address.ToString();
dt.Rows.Add(dr1);
}
}
ds.Tables.Add(dt);
}
catch (Exception ex)
{
lbl_email_count.Text = "There is a Problem in Id Or
Password!!!";
}
return ds;
}
protected void Button1_Click(object
sender, EventArgs e)
{
getcontacts();
}
public void getcontacts()
{
DataSet ds =
GetGmailContacts("Web Application!",
txt_email.Text, txtpass.Text);
if (ds.Tables.Count < 1)
{
lbl_email_count.Text = "No Contacts Found!!!!";
}
else
{
lbl_email_count.Text
= "Total Emails from your list :: " +
ds.Tables[0].Rows.Count.ToString();
GV_List.DataSource = ds;
GV_List.DataBind();
}
}
}
For more find the code in ZIp.