Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > .NET Framework 2.0
|
.NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 2.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 17th, 2009, 05:39 AM
Registered User
 
Join Date: Dec 2008
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi Baburman,

Thank you for your reply.
Now the program is connecting to Gmail.But how to retrive all inbox messages through my program. Please can you help me out.


Thank you with Warm Regards,
Gauri
 
Old February 1st, 2009, 08:06 PM
Registered User
 
Join Date: Feb 2009
Posts: 1
Thanks: 1
Thanked 0 Times in 0 Posts
Default Code with minor changes and fixed typos.

I have used this example in .net 3.5 When I first gotthe code i was full of errors.
After making a few adjustments it works great Thanks to the poster for the usefulness of the post here is the code with the changes I made "It could still be formatted a little more professionally"

publicpartialclassMailForm : Form
{
SslStream sslStream = null;
public MailForm()
{
InitializeComponent();
}
privatevoid button1_Click(object sender, EventArgs e)
{
// change cursor into wait cursor
Cursor cr = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
// create server POP3 with port 110
//Server = new TcpClient(POPServ.Text,110);
TcpClient Server = newTcpClient("pop.gmail.com", 995);
//Status.Items.Clear();
try
{
/////////////////////////////////////////////////////////////////////////
sslStream = newSslStream(Server.GetStream(), false, newRemoteCertificateValidationCallback(ValidateServerCertificate), null);
sslStream.AuthenticateAsClient(
"pop.gmail.com");
string messageData = ReadMessage(sslStream, false);
//Status.Items.Add(messageData);
string Data = "USER " + "example@gmail.com" + Environment.NewLine ;
byte[] szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
sslStream.Write(szData, 0, szData.Length);
sslStream.Flush();
messageData = ReadMessage(sslStream,
false);
//Status.Items.Add(messageData);
Data = "PASS " + "YOUR PASSWORD" + Environment.NewLine;
szData = System.Text.
Encoding.ASCII.GetBytes(Data.ToCharArray());
sslStream.Write(szData, 0, szData.Length);
sslStream.Flush();
messageData = ReadMessage(sslStream,
false);
//Status.Items.Add(messageData);
Data = "STAT" + Environment.NewLine;
szData = System.Text.
Encoding.ASCII.GetBytes(Data.ToCharArray());
sslStream.Write(szData, 0, szData.Length);
sslStream.Flush();
messageData = ReadMessage(sslStream,
false);
//Status.Items.Add(messageData);
Data = "LIST" + Environment.NewLine;
szData = System.Text.
Encoding.ASCII.GetBytes(Data.ToCharArray());
sslStream.Write(szData, 0, szData.Length);
sslStream.Flush();
messageData = ReadMessage(sslStream,
true);
//Status.Items.Add(messageData);
/////////////////////////////////////////////////////////////////////////

// back to normal cursor
Cursor.Current = cr;
}
catch (InvalidOperationException err)
{
//Status.Items.Add("Error: " + err.ToString());
}
}
publicstaticbool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
if (sslPolicyErrors == SslPolicyErrors.None)
returntrue;
else
returnfalse;
}
publicstaticstring ReadMessage(SslStream sslStream1, bool MultilineResponse)
{
byte[] buffer = newbyte[1024];
int bytes = -1;
StringBuilder messageData = newStringBuilder();
Decoder decoder = Encoding.UTF8.GetDecoder();
char[] chars;
while (true)
{
bytes = sslStream1.Read(buffer, 0, buffer.Length);
if (bytes <= 0)
break;
chars =
newchar[decoder.GetCharCount(buffer, 0, bytes)];
decoder.GetChars(buffer, 0, bytes, chars, 0);
messageData.Append(chars);
if (!MultilineResponse)
break;
elseif (messageData.ToString().EndsWith("\r\n.\r\n"))
break;
}
return messageData.ToString();
}
privatevoid button2_Click(object sender, EventArgs e)
{
// change cursor into wait cursor
Cursor cr = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;

try
{
// retrieve mail with number mail parameter
string Data = "RETR " + "1" + Environment.NewLine;
byte[] szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());

sslStream.Write(szData, 0, szData.Length);
sslStream.Flush();
string messageData = ReadMessage(sslStream, true);
webBrowser1.DocumentText = messageData;

// back to normal cursor
Cursor.Current = cr;
}
catch (InvalidOperationException err)
{
//Status.Items.Add("Error: " + err.ToString());
}
}


}





Similar Threads
Thread Thread Starter Forum Replies Last Post
Can any body help POP3 in C# coding... Bashu C# 2005 2 August 20th, 2007 01:10 PM
Microsoft SMTP POP3 HOW? bluelabs Internet Information Services 1 February 16th, 2007 10:40 PM
Fsockopne with pop3 mail vibinkrish Pro PHP 0 March 1st, 2006 11:16 AM
POP3 and ASP knightm28 SQL Server ASP 0 April 6th, 2005 04:46 AM
SMTP and POP3 for local bspradeep Classic ASP Professional 2 January 17th, 2004 04:11 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.