Read Gmail Email Attachment And Move To Any Folder In My Computer Using Console Application in c# Only..I tried POp3Client,TCpclient & Smtp..they all are working in web application..But I only need console application in c#
Here is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Net.NetworkInformation;
using System.Net.Security;
using System.Net.Sockets;
namespace FetchEmailFromGmail
{
class Program
{
static void Main(string[] args)
{
// create an instance of TcpClient
TcpClient tcpclient = new TcpClient();
tcpclient.Connect("pop.gmail.com", 995);
System.Net.Security.SslStream sslstream = new SslStream(tcpclient.GetStream());
sslstream.AuthenticateAsClient("pop.gmail.com");
StreamWriter sw = new StreamWriter(sslstream);
System.IO.StreamReader reader = new StreamReader(sslstream);
sw.WriteLine("USER someaccount@gmail.com"); sw.Flush();
sw.WriteLine("PASS somepass"); sw.Flush();
//sw.WriteLine("RETR 1");
//sw.WriteLine("STAT ");
sw.WriteLine("LIST ");
sw.Flush();
sw.WriteLine("Quit ");
sw.Flush();
string str = string.Empty;
string strTemp = string.Empty;
while ((strTemp = reader.ReadLine()) != null)
{
if (".".Equals(strTemp))
{
break;
}
if (strTemp.IndexOf("-ERR") != -1)
{
break;
}
str += strTemp;
}
Console.Write(str);
reader.Close();
sw.Close();
tcpclient.Close(); // close the connection
Console.ReadLine();
}
}
}