Tutorials
Resources
Forum
Reviews
Communities
Interview
Jobs
Projects
Training
Your
Ad
Here
Silverlight Games
|
Mentor
|
Code Converter
|
Articles
|
Code Factory
|
Computer Jokes
|
Members
|
Peer Appraisal
|
IT Companies
|
Bookmarks
|
Polls
|
Revenue Sharing
|
Lobby
|
Gift Shop
|
Prizes & Awards
My Profile
Sign In
Register
AdSense Revenue
Active Members
Today
Nikhil Gaur
(70)
Nadheera V
(20)
krishnavenikal...
(12)
Last 7 Days
Nikhil Gaur
(621)
Anil Kumar ...
(582)
Abhisek Panda
(445)
more...
Resources
»
Code Snippets
»
ASP.NET WebForms
»
Read emails in GMail account from your ASP.Net application
Posted Date: 23 Jun 2008
Resource Type:
Code Snippets
Category:
ASP.NET WebForms
Author:
Satalaj More
Member Level:
Silver
Rating:
Points
: 10
Hi,
Here is simple way of reading your gmail email using ASP.net web application
Before using this code make sure you are able to access your gmail email using outlook
if not then login to www.gmail.com click on settings => pop => check to access email outside gmail web client
Refer POP rfc http://www.faqs.org/rfcs/rfc1939
Steps
1. create new asp.net web application
2. add one button in it
3. on button click write following code
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;
protected void Button9_Click(object sender, EventArgs e)
{
try
{
TcpClient tcpclient = new TcpClient(); // create an instance of TcpClient
tcpclient.Connect("pop.gmail.com", 995); // HOST NAME POP SERVER and gmail uses port number 995 for POP
System.Net.Security.SslStream sslstream = new SslStream(tcpclient.GetStream()); // This is Secure Stream // opened the connection between client and POP Server
sslstream.AuthenticateAsClient("pop.gmail.com"); // authenticate as client
//bool flag = sslstream.IsAuthenticated; // check flag
System.IO.StreamWriter sw = new StreamWriter(sslstream); // Asssigned the writer to stream
System.IO.StreamReader reader = new StreamReader(sslstream); // Assigned reader to stream
sw.WriteLine("USER your_gmail_user_name@gmail.com"); // refer POP rfc command, there very few around 6-9 command
sw.Flush(); // sent to server
sw.WriteLine("PASS your_gmail_password");
sw.Flush();
sw.WriteLine("RETR 1"); // this will retrive your first email
sw.Flush();
sw.WriteLine("Quit "); // close the connection
sw.Flush();
string str = string.Empty;
string strTemp = string.Empty;
while ((strTemp = reader.ReadLine()) != null)
{
if (strTemp == ".") // find the . character in line
{
break;
}
if (strTemp.IndexOf("-ERR") != -1)
{
break;
}
str += strTemp;
}
Response.Write(str);
Response.Write("
" + "Congratulation.. ....!!! You read your first gmail email ");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
For more details, visit
http://weblogs.asp.net/satalajmore/
Responses
No responses found. Be the first to respond and make money from
revenue sharing program
.
Feedbacks
Popular Tags
What are tags ?
Search Tags
Sign In
to add tags.
(No tags found.)
Post Feedback
This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must
Sign In
to post a response.
Next Resource:
Javascript Confirm Box on ASP.NET linkbutton
Previous Resource:
Create a permanent cookie
Return to Discussion Resource Index
Post New Resource
Category:
ASP.NET WebForms
Post resources and
earn money
!
Related Resources
Javascript Confirm Box on ASP.NET linkbutton
How To Adapt A Master Page while Designing .aspx Pages
programmatically add controls to a table row
How to bind Radio Button List throuh Sql Server
ScrollBar for GridView
Cross Page PostBack
dotNet Slackers
About Us
Contact Us
Privacy Policy
Terms Of Use