I have a project (Visual C# 2010 Express) that requires me to download my Gmail inbox in the background, then parse through them and put the ones that I need in a ListBox or something. I haven't been able to install the Google API, as it says I need .NET 2.0 and I don't know how to use NuGet. Is there a way to do this without the Google API, and if not, how can I install it?
-
You don't install an API, you access an API. You can download the Google .net client library but you dont install that either. Nuget package location is: Install-Package Google.Apis.Gmail.v1 try and google how to use Nuget referencing all the dlls yourself will be a pain.– Linda Lawton - DaImToSep 10, 2015 at 7:23
Add a comment
|
1 Answer
No you dont require to have Google API for getting(downloading) emails from Gmail account. You can read more about Reading Gmail Inbox Message
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Net.NetworkInformation;
using System.Net.Security;
using System.Net.Sockets;
namespace mail
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Imap client = new Imap();
// connect to server
client.Connect("imap.gmail.com", 993, SslMode.Implicit);
// authenticate
client.Login("username", "password");
// select folder
client.SelectFolder("Inbox");
int NoOfEmailsPerPage = 10;
int totalEmails = client.CurrentFolder.TotalMessageCount;
// get message list - envelope headers
ImapMessageCollection messages = client.GetMessageList(ImapListFields.Envelope);
// display info about each message
foreach (ImapMessageInfo message in messages)
{
TableCell noCell = new TableCell();
noCell.CssClass = "emails-table-cell";
noCell.Text = Convert.ToString(message.To);
TableCell fromCell = new TableCell();
fromCell.CssClass = "emails-table-cell";
fromCell.Text = Convert.ToString(message.From);
TableCell subjectCell = new TableCell();
subjectCell.CssClass = "emails-table-cell";
subjectCell.Style["width"] = "300px";
subjectCell.Text = Convert.ToString(message.Subject);
TableCell dateCell = new TableCell();
dateCell.CssClass = "emails-table-cell";
if (message.Date.OriginalTime != DateTime.MinValue)
dateCell.Text = message.Date.OriginalTime.ToString();
TableRow emailRow = new TableRow();
emailRow.Cells.Add(noCell);
emailRow.Cells.Add(fromCell);
emailRow.Cells.Add(subjectCell);
emailRow.Cells.Add(dateCell);
EmailsTable.Rows.AddAt(2 + 0, emailRow);
}
int totalPages;
int mod = totalEmails % NoOfEmailsPerPage;
if (mod == 0)
totalPages = totalEmails / NoOfEmailsPerPage;
else
totalPages = ((totalEmails - mod) / NoOfEmailsPerPage) + 1;
}
}
}
-
-
2Yes you can do that have a look on Reading Mail in Windows form Using C#– Mohit SSep 10, 2015 at 2:25
-
@AgoraStudent Does it helped you? If Yes you can accept it as answer and you can say thanks by upvoting the answer.– Mohit SSep 10, 2015 at 3:36
-
Does that still work I thought the client login servers where shut down? I normally use Oauth2. Sep 10, 2015 at 7:21
-
@MohitShrivastava I'm still working on it. I'll mark it answered if it helps though Sep 11, 2015 at 2:43