Simple C# Hotmail Downloader

Discussion in 'Web Development and Programming' started by Cerberus, Apr 7, 2013.

  1. Cerberus

    Cerberus Admin Talk Staff

    Joined:
    May 3, 2009
    Messages:
    1,031
    Likes Received:
    500
    This is something I use quite a lot. Normally, I would call it from one of my other programs and do 100s or 1000s of hotmails at once using it. It is great for pulling things you need from hotmail. The way it sits is it downloads all emails in your hotmail and saves them to txt. Which makes them Parse ready for whatever info I need from them. Or, if I am to do alot I would define what I want from the body of the emails and only save that.. Parse on the go :) But, I thought I would share since Brandon mentioned he was looking to check out more C#. This uses OpenPop.dll. And some of this code can be found on their site. I take no credit for all the code. I use what I need at will.. So credit to whoever and such

    Dont ask me why the colors I guess I was just having fun that day LOL.. Also, feel free to modify and use at will. I attached the compiled version along with the dll file :) Enjoy

    Also to test simply run the file from a prompt : HMD.exe emailgoeshere thenpasswordhere

    Code:
    Code:
    using System;
    using System.IO;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using OpenPop.Pop3;
    using OpenPop.Mime;
    using OpenPop.Mime.Header;
    using OpenPop.Common;
    using System.Data;
     
    namespace Hotmail_Downloader
    {
      class Program
      {
          static void Main(string[] args)
          {
        Console.Title = "Hotmail Downloader";
        Console.ForegroundColor = ConsoleColor.Yellow;
        Console.WriteLine("Welcome to Hotmail Grabber by Cerberus");
        string hostname = "pop3.live.com";
        int port = 995;
        bool useSsl = true;
     
        string botpath = Directory.GetCurrentDirectory();
        string username = args[0];
        string password = args[1];
     
     
       
            // Create the POP3 client
            Pop3Client client = new Pop3Client();
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Connecting to Hotmail");
     
            // Connect to hotmail using ssl
            try { client.Connect(hostname, port, useSsl); }
            catch (Exception ex)
            {
                System.IO.StreamWriter file = new System.IO.StreamWriter(botpath + "/Error.txt", true);
                file.WriteLine(username + password);
                file.Close();
                Console.WriteLine(ex);
                Environment.Exit(0);
            }
            // Authenticate the cient
            try { client.Authenticate(username, password); }
            catch (Exception ex)
            {
                System.IO.StreamWriter file = new System.IO.StreamWriter(botpath + "/Error.txt", true);
                file.WriteLine(username + password);
                file.Close();
                Console.WriteLine(ex);
                Environment.Exit(0);
            }
     
     
            // Get the number of messages in the inbox
            int messageCount = client.GetMessageCount();
            Console.WriteLine("Grabbing messages Now");
     
            // Loop through the messages if they exist
            if (messageCount > 0)
            {
                for (int i = messageCount; i >= 1; i -= 1)
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine(i + "/" + messageCount);
                    // Get the message by index
                    Message message = client.GetMessage(i);
                   
                    // Get the first plain text version of the email
                    MessagePart plainText = message.FindFirstHtmlVersion(); // FindFirstHtmlVersion(); // FindFirstPlainTextVersion(); //
     
                    if (plainText == null) { continue; }
     
                    // Get the body from the plain text version of the email
                    string body = plainText.GetBodyAsText();
     
                        //Write to txt
                        System.IO.StreamWriter file = new System.IO.StreamWriter(botpath + "/ " + username + i + ".txt");
                        file.WriteLine(body);
                        file.Close();
                 
                 
                }
     
            }
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Saving and Logging Out");
     
            System.Threading.Thread.Sleep(500);
            client.Disconnect();
          }
      }
    }
    
     

    Attached Files:

    • HMD.rar
      File size:
      25.2 KB
      Views:
      392
    Brandon likes this.

Share This Page