1

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();
        }
    }
}
Prix
  • 19,417
  • 15
  • 73
  • 132
kushal
  • 17
  • 3
  • I can't test your code at the moment. What is the problem? – Asad Saeeduddin Sep 28 '13 at 05:09
  • 3
    I have removed your credentials from the code and recommend you to change your password ASAP to avoid losing the account, have also flagged for moderation attention so they can permanently remove your credentials from the reviews. – Prix Sep 28 '13 at 05:18
  • Please follow the following post: http://stackoverflow.com/questions/545724/using-c-sharp-net-librarires-to-check-for-imap-messages-from-gmail-servers – Khurram Ishaque Sep 28 '13 at 05:34
  • Thank you Prix..I Forgot To Delete My Credentials.. – kushal Sep 28 '13 at 18:00
  • Hi ! Asad..I want a simple C# console application..that read my gmail emails with attachment and store that attachment in particular folder..Plz help me.. – kushal Sep 28 '13 at 18:02
  • Hi ! Khurram Ishaque..I tried you solution link..but i cant able to solve my problem..can you please..give me sample code that i simply copy paste in my application..?? – kushal Sep 28 '13 at 18:08

0 Answers0