 |
|
 |
me this code works fine, but when I read mail from hotmail I can not .. that changes would have to
|
|
|
|
 |
|
 |
I have a POP3 Server and POP3 Port.
I couldn't connect it using your code.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net;
using System.Net.Sockets;
using System.IO;
namespace FYPJ_Remote_Control_Via_Email
{
public partial class Form1 : Form
{
//private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
}
/*protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}*/
[STAThread]
static void MainRun()
{
Application.Run(new Form1());
}
/* protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}*/
private void btnConnect_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(txtServer.Text, 110);
listStatus.Items.Clear();
try
{
// initialization
Meiqi = Server.GetStream();
Shuwen = new StreamReader(Server.GetStream());
listStatus.Items.Add(Shuwen.ReadLine());
// Login Process
Data = "USER " + txtUserName.Text + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
Meiqi.Write(szData, 0, szData.Length);
listStatus.Items.Add(Shuwen.ReadLine());
Data = "PASS " + txtPass.Text + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
Meiqi.Write(szData, 0, szData.Length);
listStatus.Items.Add(Shuwen.ReadLine());
// Send STAT command to get information ie: number of mail and size
Data = "STAT" + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
Meiqi.Write(szData, 0, szData.Length);
listStatus.Items.Add(Shuwen.ReadLine());
// change enabled - disabled button
btnConnect.Enabled = false;
btnDisconnect.Enabled = true;
btnRetrieve.Enabled = true;
// back to normal cursor
Cursor.Current = cr;
}
catch (InvalidOperationException err)
{
listStatus.Items.Add("Error: " + err.ToString());
}
}
private void btnDisconnect_Click(object sender, EventArgs e)
{
// change cursor into wait cursor
Cursor cr = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
// Send QUIT command to close session from POP server
Data = "QUIT" + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
Meiqi.Write(szData, 0, szData.Length);
listStatus.Items.Add(Shuwen.ReadLine());
//close connection
Meiqi.Close();
Shuwen.Close();
// change enabled - disabled button
btnConnect.Enabled = true;
btnDisconnect.Enabled = false;
btnRetrieve.Enabled = false;
// back to normal cursor
Cursor.Current = cr;
}
private void btnRetrieve_Click(object sender, EventArgs e)
{
// change cursor into wait cursor
Cursor cr = Cursor.Current;
Cursor.Current = Cursors.WaitCursor;
string szTemp;
txtMessage.Clear();
try
{
// retrieve mail with number mail parameter
Data = "RETR " + txtMailNumber.Text + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
Meiqi.Write(szData, 0, szData.Length);
szTemp = Shuwen.ReadLine();
if (szTemp[0] != '-')
{
while (szTemp != ".")
{
txtMessage.Text += szTemp;
szTemp = Shuwen.ReadLine();
}
}
else
{
listStatus.Items.Add(szTemp);
}
// back to normal cursor
Cursor.Current = cr;
}
catch (InvalidOperationException err)
{
listStatus.Items.Add("Error: " + err.ToString());
}
}
private void btnExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
public TcpClient Server;
public NetworkStream Meiqi;
public StreamReader Shuwen;
public string Data;
public byte[] szData;
public string CRLF = "\r\n";
private void btnLogin_Click(object sender, EventArgs e)
{
string strserver = txtServer.Text;
string strusername = txtUserName.Text;
string strpassword = txtPass.Text;
strserver = "995";
strusername = "fypjms.gmail.com";
strpassword = "hello";
//Cursor cr = Cursor.Current;
//Cursor.Current = Cursors.WaitCursor;
Server = new TcpClient(strserver, 995);
//Status.Items.Clear();
try
{
// initialization
Meiqi = Server.GetStream();
Shuwen = new StreamReader(Server.GetStream());
//Status.Items.Add(RdStrm.ReadLine());
//Label1.Text = Label1.Text + RdStrm.ReadLine();
listStatus.Items.Add(Shuwen.ReadLine());
// Login Process
Data = "USER " + strusername + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
Meiqi.Write(szData, 0, szData.Length);
//Status.Items.Add(RdStrm.ReadLine());
//Label1.Text = Label1.Text + RdStrm.ReadLine();
listStatus.Items.Add(Shuwen.ReadLine());
Data = "PASS " + strpassword + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
Meiqi.Write(szData, 0, szData.Length);
//Status.Items.Add(RdStrm.ReadLine());
//Label1.Text = Label1.Text + RdStrm.ReadLine();
listStatus.Items.Add(Shuwen.ReadLine());
}
catch (InvalidOperationException err)
{
//Status.Items.Add("Error: " + err.ToString());
//Label1.Text = "Error: " + err.ToString();
listStatus.Items.Add("Error: " + err.ToString());
}
}
}
}
|
|
|
|
 |
|
 |
What is the "Mail Number"?
|
|
|
|
 |
|
 |
It is an ID number the server gives to each message. Begins in 1 and ends in message count.You must use this ID numbers to for example Retrieve the message (RET 3) means you are reading the third message... also for other things like Deleting messages from the server (DELE 2)--> Delete message with ID 2.
Each time you get fresh information from the server this IDs can change, they are only useful for the current session.
Good Luck.
|
|
|
|
 |
|
 |
Hi,
I was able to successfully write and read mail from the mail server. But how do I save or move file to another folder like Inbox\new folder
Thanking you,
Nirmala
|
|
|
|
 |
|
 |
What is the "Mail Number"?
|
|
|
|
 |
|
 |
hiii im using the code but im not able to download the attachment
|
|
|
|
 |
|
 |
hi
it is good. it is working fine
thanks
now i can change web based program
i am using ur code
but i got error in web based program
i got error in System.NullReferenceException: Object reference not set to an instance of an object. (in retrieve button event and disconnect button event => (line) NetStrm.Write(szData, 0, szData.Length);)
//my code start here
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.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Net;
using System.Net.Sockets;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
public TcpClient testServername;
public NetworkStream NetStrm;
public StreamReader RdStrm;
public string Data;
public byte[] szData;
public string CRLF = "\r\n";
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string strpopservername = txtpopservername.Text;
string strusername = txtusername.Text;
string strpassword = txtpassword.Text;
strpopservername = "192.168.50.2";
strusername = "yogaraj@rrinfotech.in";
strpassword = "yoga123";
//Cursor cr = Cursor.Current;
//Cursor.Current = Cursors.WaitCursor;
testServername = new TcpClient(strpopservername, 110);
//Status.Items.Clear();
try
{
// initialization
NetStrm = testServername.GetStream();
RdStrm = new StreamReader(testServername.GetStream());
//Status.Items.Add(RdStrm.ReadLine());
//Label1.Text = Label1.Text + RdStrm.ReadLine();
ListBox1.Items.Add(RdStrm.ReadLine());
// Login Process
Data = "USER " + strusername + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData, 0, szData.Length);
//Status.Items.Add(RdStrm.ReadLine());
//Label1.Text = Label1.Text + RdStrm.ReadLine();
ListBox1.Items.Add(RdStrm.ReadLine());
Data = "PASS " + strpassword + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData, 0, szData.Length);
//Status.Items.Add(RdStrm.ReadLine());
//Label1.Text = Label1.Text + RdStrm.ReadLine();
ListBox1.Items.Add(RdStrm.ReadLine());
// Send STAT command to get information ie: number of mail and size
Data = "STAT" + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData, 0, szData.Length);
//Status.Items.Add(RdStrm.ReadLine());
//Label1.Text = Label1.Text + RdStrm.ReadLine();
ListBox1.Items.Add(RdStrm.ReadLine());
// change enabled - disabled button
Butconnect.Enabled = false;
Butdisconnect.Enabled = true;
ButRetrieve.Enabled = true;
//ConnectBtn.Enabled = false;
// DisconnectBtn.Enabled = true;
// RetrieveBtn.Enabled = true;
// back to normal cursor
//Cursor.Current = cr;
}
catch (InvalidOperationException err)
{
//Status.Items.Add("Error: " + err.ToString());
//Label1.Text = "Error: " + err.ToString();
ListBox1.Items.Add("Error: " + err.ToString());
}
}
protected void Butdisconnect_Click(object sender, EventArgs e)
{
//NetStrm = testServername.GetStream();
// Send QUIT command to close session from POP server
Data = "QUIT" + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData, 0, szData.Length);
ListBox1.Items.Add(RdStrm.ReadLine());
//close connection
NetStrm.Close();
RdStrm.Close();
// change enabled - disabled button
//ConnectBtn.Enabled = true;
//DisconnectBtn.Enabled = false;
//RetrieveBtn.Enabled = false;
Butconnect.Enabled = true;
Butdisconnect.Enabled = false;
ButRetrieve.Enabled = false;
}
protected void ButRetrieve_Click(object sender, EventArgs e)
{
// change cursor into wait cursor
//Cursor cr = Cursor.Current;
//Cursor.Current = Cursors.WaitCursor;
string szTemp;
//Message.Clear();
Label2.Text = "";
try
{
// retrieve mail with number mail parameter
Data = "RETR " + txtnumber.Text + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
//NetStrm.Write(szData, 0, szData.Length);
NetStrm.Write(szData, 1, szData.Length);
szTemp = RdStrm.ReadLine();
if (szTemp[0] != '-')
{
while (szTemp != ".")
{
Label2.Text += szTemp + CRLF;
szTemp = RdStrm.ReadLine();
}
}
else
{
ListBox1.Items.Add(szTemp);
}
// back to normal cursor
//Cursor.Current = cr;
}
catch (InvalidOperationException err)
{
ListBox1.Items.Add("Error: " + err.ToString());
}
catch (System.Exception ex)
{
ListBox1.Items.Add("Error : " + ex.ToString());
}
}
}
//my code end here
|
|
|
|
 |
|
 |
Hi,
It gives error in this line
Status.Items.Add(RdStrm.ReadLine());
Error:- Value can't be null
Please tell me the solution
Thanks
|
|
|
|
 |
|
 |
You get that error if some of your server info is wrong, such as Server adress or Port, or UserName
|
|
|
|
 |
|
 |
I got error message that "value cannot be null" on line Status.Items.Add(RdStrm.ReadLine());
The Function RdStrm.ReadLine() will return NULL value, which we can't pass into Status.Items.Add()method. So how overcome from this issue? How read the data of mail using ReadLine().
Narendra Pipaliya
-- modified at 4:09 Friday 30th November, 2007
|
|
|
|
 |
|
 |
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
could anybody plz tell me how to solve it or what is the root cause of the exception
Thanks in Advance
Abhishek Jain
|
|
|
|
 |
|
 |
Hi everyone:
What can i fill in for:
Pop server:
User:
Password:
could someone give me an example?
Thank you very much!
IEn
|
|
|
|
 |
|
 |
I download this project to my computer.Then I run.but I don't understand mailnumber is? I write number on it ,then I click retrieve but it show error:
Err unvalid message number.Can you help me about this problem,please? Thanks
|
|
|
|
 |
|
 |
how can i have to crete the password and user name
|
|
|
|
 |
|
 |
hi all
i have problem with retrieving mail
first of all i dont know where my messages are displayed to choose a number from
and i am sue thre is mail in my mailbox
I GET THIS EVERY TIME I LOG ON
-ERR command valid only in transaction state
thnx all
Mostafa Ismail
|
|
|
|
 |
|
 |
Hello,
I am redaing file from pop3 server.But if attachment is coming through .doc
file ,program is not able to read.It is showing the funny charcater....
Please let me know how can i read .doc file in proper format..
Neeraj Jain
-- modified at 3:46 Saturday 28th April, 2007
|
|
|
|
 |
|
 |
thx your sharing first,i have a question want to ask you,please give me a hand,the question is can i retrieve a pop3 mail into outlook default folder?
thx!
|
|
|
|
 |
|
 |
I have faced the problem while connecting the pop3 server in my application. Actually the server is connected but when disconnect the server, it shows the following error.
Data = "QUIT " + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData,0,szData.Length);
NetStrm.Close();
Object reference not set to an instance of an object.
Help me.
SR Ranjini
|
|
|
|
 |
|
 |
I got the same problem. Im not sure what the problem is but i think is has something to do with the connection to the mail server beacuse i moved the code from retrive button to connect button
Like this:
string szTemp;
try
{
// retrieve mail with number mail parameter
Data = "RETR " + "1" + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
NetStrm.Write(szData, 0, szData.Length);
szTemp = RdStrm.ReadLine();
if (szTemp[0] != '-')
{
while (szTemp != ".")
{
lblStatus.Text += szTemp;
szTemp = RdStrm.ReadLine();
}
}
else
{
lblStatus.Text = szTemp;
}
}
catch (InvalidOperationException err)
{
lblStatus.Text = "Error: " + err.ToString();
}
and then i worked for me. when i connected to the mailserver using pop3 i recived also mail
hope this help u
gohil
|
|
|
|
 |
|
 |
when i click the connection button,then there is a error in the "Server = new TcpClient(POPServ.Text,110);", but i don't know how to deal with error.
kraster
|
|
|
|
 |
|
 |
Hi,
The code gave me a good starter.
Thanks.
|
|
|
|
 |
|
 |
What modifications need to be made to connect to an SSL POP3 Mail Server?
Thanks for your help!
T
|
|
|
|
 |
|
 |
Check my blog entry for a way to connect to POP3 via SSL using C#:
http://knab.ws/blog/index.php?/archives/2-Secure-POP3-client-for-C.html
|
|
|
|
 |
|
 |
Hello,
I tried with the changes you requested for SSL but i am getting i/o exception. If you have working code for POP using SSL then do send me on bhavesh@sungrace.com.
-Bhavesh
|
|
|
|
 |