473,382 Members | 1,165 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Read mail from the mail server (Pop3) using TCPClient

Hello,

Please cnay one can tell me how to read mail as formatted.... i have made
some code using that able to read but not able to serialize..... so am i need
to parse the HTML, or is there any class using that i can directly get the
full info ablt the mail, like TO,From,Subject,Body,Attachments,

Below is the code which i develop,

using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Sockets;
using System.IO;
using System.Web.Mail;

namespace testMail
{
class Program
{
static void Main(string[] args)
{
try
{
TcpClient Server;
NetworkStream NetStrm;
StreamReader RdStrm;
string Data;
byte[] szData;
string CRLF = "\r\n";

if (args.Length < 3)
return;

string _Server = args[0];
string _User = args[1];
string _Pwd = args[2];
string status;
// create server POP3 with port 110
Server = new TcpClient(_Server, 110);
NetStrm = Server.GetStream();
RdStrm = new StreamReader(Server.GetStream());
Console.WriteLine(RdStrm.ReadLine());

// Login Process
Data = "USER " + _User + CRLF;
szData =
System.Text.Encoding.ASCII.GetBytes(Data.ToCharArr ay());
NetStrm.Write(szData, 0, szData.Length);
Console.WriteLine(RdStrm.ReadLine());

Data = "PASS " + _Pwd + CRLF;
szData =
System.Text.Encoding.ASCII.GetBytes(Data.ToCharArr ay());
NetStrm.Write(szData, 0, szData.Length);
Console.WriteLine(RdStrm.ReadLine());

// Send STAT command to get information ie: number of mail
and size
Data = "STAT" + CRLF;
szData =
System.Text.Encoding.ASCII.GetBytes(Data.ToCharArr ay());
NetStrm.Write(szData, 0, szData.Length);
string messagesC = RdStrm.ReadLine();
Console.WriteLine(messagesC);

int messageCounter = int.Parse(messagesC.Split(' ')[1]);
string szTemp;
string message="";
// retrieve mail with number mail parameter
Data = "RETR " + messageCounter + CRLF;
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArr ay());
NetStrm.Write(szData,0,szData.Length);

szTemp = RdStrm.ReadLine();
if(szTemp[0]!='-')
{

while(szTemp!=".")
{
message += szTemp+CRLF;
szTemp = RdStrm.ReadLine();
}
}
else
{
Console.WriteLine(szTemp);
}

Console.WriteLine(message);
// Send QUIT command to close session from POP server
Data = "QUIT" + CRLF;
szData =
System.Text.Encoding.ASCII.GetBytes(Data.ToCharArr ay());
NetStrm.Write(szData, 0, szData.Length);
Console.WriteLine(RdStrm.ReadLine());

//close connection
NetStrm.Close();
RdStrm.Close();

}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Console.WriteLine("Finished....");
Console.ReadLine();
}
}
}

Thanks,
Prasanta
Oct 13 '06 #1
1 11278

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Programmer | last post by:
Hi all I wan't to know if i'm able to read mail from a mail server. My mail server is a pop3 server (UNIX) and i want to be able to get the mails from an aspx or an asmx. with out using external...
1
by: oni | last post by:
hi all, the program should be able to log on to a pop mail account and need to just read its headers and display. any help in this regard highly apperecialted. code pref VB.NET thankz in...
3
by: jamal | last post by:
HI guys I want to make a program that will read my external pop3 e-mail account and save them to an access/sql file on my workstation. what you guys think ? Can I make something like this with...
2
by: Abhi | last post by:
i need to create a user in web mail using dotnet coad by using webmailserver api ex: xxx is my webmail then i want to create to a user in that webmail xxx ex: yyy@xxx.com how i should do in...
1
by: Prasanta | last post by:
Hello, How to read a mail from the mail server as formatted. I am able to read the mail as row HTML, is there any class, or something method using that i can easily get the all info of that...
0
by: aknigam1 | last post by:
Hello, I make a web application for receive mail from POP3 from the our domain by passing our pop3 server name and our user id and password . And i'm able to read (receive) only mail from Inbox....
4
by: =?Utf-8?B?QWxwYW5h?= | last post by:
I am making a thin email client and want to get emails from a pop3 server...Is there any built in support in C# to get emails from a pop3 server and parse the email to show up on the UI ?
1
by: rodny.romero | last post by:
Somebody can help me with an example of like Reading post office with VB.Net using protocol POP3, I have obtained the commandos or instructions that protocol POP3 supports, but I have not been able...
3
by: =?Utf-8?B?VHJlY2l1cw==?= | last post by:
Hello, Newsgroupians: I'm creating an application that will read emails from GMail, using the System.Net.Sockets.TcpClient and POP protocol. However, I am having a problem with my SslStream. ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.