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 mail, like as TO,From,Subject,Body. here I am
attaching my coe which i developed.
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();
}
}
}
waiting for the reply....
Thanks
Prasanta 1 5668
Hi,
I use http://www.codeproject.com/cs/intern...pop3client.asp, which caters
for all my requirements, hope this helps you too.
Cheers,
Quentin
"Prasanta" <Pr******@discussions.microsoft.comwrote in message
news:23**********************************@microsof t.com...
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 mail, like as TO,From,Subject,Body. here I
am
attaching my coe which i developed.
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();
}
}
}
waiting for the reply....
Thanks
Prasanta
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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...
|
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...
|
by: Prasanta |
last post by:
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...
| |
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....
|
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 ?
|
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...
|
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.
...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |