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