public static void Run()
        {
            Pop3Client client = new Pop3Client();

            client.Host            = "pop.gmail.com";
            client.Port            = 995;
            client.SecurityOptions = SecurityOptions.SSLImplicit;
            client.Username        = "******";
            client.Password        = "******";

            try
            {
                // ExStart:ListMessagesAsynchronouslyWithMailQuery
                MailQueryBuilder builder = new MailQueryBuilder();
                builder.Subject.Contains("Subject");
                MailQuery    query                 = builder.GetQuery();
                IAsyncResult asyncResult           = client.BeginListMessages(query);
                Pop3MessageInfoCollection messages = client.EndListMessages(asyncResult);
                // ExEnd:ListMessagesAsynchronouslyWithMailQuery
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
예제 #2
0
        public static void Run()
        {
            //ExStart:1
            // Create an instance of the Pop3Client class
            Pop3Client pop3Client = new Pop3Client();

            pop3Client.Host     = "<HOST>";
            pop3Client.Port     = 995;
            pop3Client.Username = "******";
            pop3Client.Password = "******";

            pop3Client.ConnectionsQuantity = 5;
            pop3Client.UseMultiConnection  = MultiConnectionMode.Enable;
            DateTime multiConnectionModeStartTime     = DateTime.Now;
            Pop3MessageInfoCollection messageInfoCol1 = pop3Client.ListMessages();
            TimeSpan multiConnectionModeTimeSpan      = DateTime.Now - multiConnectionModeStartTime;

            pop3Client.UseMultiConnection = MultiConnectionMode.Disable;
            DateTime singleConnectionModeStartTime    = DateTime.Now;
            Pop3MessageInfoCollection messageInfoCol2 = pop3Client.ListMessages();
            TimeSpan singleConnectionModeTimeSpan     = DateTime.Now - singleConnectionModeStartTime;

            Console.WriteLine("multyConnectionModeTimeSpan: " + multiConnectionModeTimeSpan.TotalMilliseconds);
            Console.WriteLine("singleConnectionModeTimeSpan: " + singleConnectionModeTimeSpan.TotalMilliseconds);
            double performanceRelation = singleConnectionModeTimeSpan.TotalMilliseconds / multiConnectionModeTimeSpan.TotalMilliseconds;

            Console.WriteLine("Performance Relation: " + performanceRelation);
            //ExEnd: 1

            Console.WriteLine("Pop3ListMessagesWithMultiConnection executed successfully.");
        }
예제 #3
0
파일: Form1.cs 프로젝트: inox85/emailSaver
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a POP3 client
            Pop3Client pop = new Pop3Client();

            //Set host, username, password etc. for the client
            pop.Host      = "pop.chemitec.it";
            pop.Username  = "******";
            pop.Password  = "******";
            pop.Port      = 995;
            pop.EnableSsl = true;

            //Connect the server
            pop.Connect();
            //Get the first message by its sequence number
            Pop3MessageInfoCollection m = pop.GetAllMessages();
            MailMessage message         = pop.GetMessage(54);

            //Parse the message
            message.Save("Sample.msg", MailMessageFormat.Msg);

            Console.WriteLine("------------------ HEADERS ---------------");
            Console.WriteLine("From : " + message.From.ToString());
            Console.WriteLine("To : " + message.To.ToString());
            Console.WriteLine("Date : " + message.Date.ToString(CultureInfo.InvariantCulture));
            Console.WriteLine("Subject: " + message.Subject);
            Console.WriteLine("------------------- BODY -----------------");
            Console.WriteLine(message.BodyText);
            Console.WriteLine("------------------- END ------------------");
            //Save the message to disk using its subject as file name
            message.Save(message.Subject + ".eml", MailMessageFormat.Eml);
            Console.WriteLine("Message Saved.");
        }
예제 #4
0
        public static void Run()
        {
            //ExStart:1
            // Create an instance of the Pop3Client class
            Pop3Client pop3Client = new Pop3Client();

            pop3Client.Host     = "<HOST>";
            pop3Client.Port     = 995;
            pop3Client.Username = "******";
            pop3Client.Password = "******";

            Pop3MessageInfoCollection messageInfoCol = pop3Client.ListMessages();

            Console.WriteLine("ListMessages Count: " + messageInfoCol.Count);
            int[]    sequenceNumberAr = messageInfoCol.Select((Pop3MessageInfo mi) => mi.SequenceNumber).ToArray();
            string[] uniqueIdAr       = messageInfoCol.Select((Pop3MessageInfo mi) => mi.UniqueId).ToArray();

            IList <MailMessage> fetchedMessagesBySNumMC = pop3Client.FetchMessages(sequenceNumberAr);

            Console.WriteLine("FetchMessages-sequenceNumberAr Count: " + fetchedMessagesBySNumMC.Count);

            IList <MailMessage> fetchedMessagesByUidMC = pop3Client.FetchMessages(uniqueIdAr);

            Console.WriteLine("FetchMessages-uniqueIdAr Count: " + fetchedMessagesByUidMC.Count);
            //ExEnd: 1

            Console.WriteLine("Pop3FetchGroupMessages executed successfully.");
        }
예제 #5
0
        public static void Run()
        {
            // ExStart:RetrieveMessagesAsynchronously
            Pop3Client client = new Pop3Client();

            client.Host            = "pop.gmail.com";
            client.Port            = 995;
            client.SecurityOptions = SecurityOptions.SSLImplicit;
            client.Username        = "******";
            client.Password        = "******";

            try
            {
                Pop3MessageInfoCollection messages = client.ListMessages();
                Console.WriteLine("Total Number of Messages in inbox:" + messages.Count);
                AutoResetEvent evnt     = new AutoResetEvent(false);
                MailMessage    message  = null;
                AsyncCallback  callback = delegate(IAsyncResult ar)
                {
                    message = client.EndFetchMessage(ar);
                    evnt.Set();
                };
                client.BeginFetchMessage(messages[0].SequenceNumber, callback, null);
                evnt.WaitOne();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            // ExEnd:RetrieveMessagesAsynchronously
        }
예제 #6
0
        public static void Run()
        {
            string dataDir = RunExamples.GetDataDir_POP3();

            // ExStart:Pop3ClientActivityLogging
            Pop3Client client = new Pop3Client("pop.gmail.com", 995, "*****@*****.**", "password");

            // Set security mode
            client.SecurityOptions = SecurityOptions.Auto;

            try
            {
                // Get the message info collection
                Pop3MessageInfoCollection list = client.ListMessages();

                // Download each message
                for (int i = 0; i < list.Count; i++)
                {
                    // Save the EML file locally
                    client.SaveMessage(list[i].UniqueId, dataDir + list[i].UniqueId + ".eml");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            // ExEnd:Pop3ClientActivityLogging
        }
        public static void Run()
        {
            try
            {
                // Create a POP3 client
                Pop3Client client;
                client = new Pop3Client();

                // Basic settings (required)
                client.Host            = "pop.gmail.com";
                client.Username        = "******";
                client.Password        = "******";
                client.Port            = 995;
                client.SecurityOptions = SecurityOptions.SSLImplicit;

                // ExStart:CheckGmailMessageInformation
                // Get the list of messages in the mailbox and Iterate through the messages
                Pop3MessageInfoCollection infos = client.ListMessages();
                foreach (Pop3MessageInfo info in infos)
                {
                    Console.Write("ID:" + info.UniqueId);
                    Console.Write("Index number:" + info.SequenceNumber);
                    Console.Write("Subject:" + info.Subject);
                    Console.Write("Size:" + info.Size);
                }
                // ExEnd:CheckGmailMessageInformation
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
예제 #8
0
        public virtual bool TryGetMessagesInfo(out Pop3MessageInfoCollection infoCollection, out string errorMessage)
        {
            lock (this)
            {
                if (this.State != EPop3ClientState.Awaiting)
                {
                    infoCollection = null;
                    errorMessage   = "Pop3Client doesn't allow executing multiple operations simulteneously in a few threads using one object";
                    return(false);
                }
                this.State = EPop3ClientState.Busy;
            }
            if (this.ConnectionState != EPop3ConnectionState.Authenticated)
            {
                infoCollection = null;
                errorMessage   = "The command cannot be executed in this state";
                lock (this)
                {
                    this.State = EPop3ClientState.Awaiting;
                }
                return(false);
            }
            bool flag = this._TryGetMessagesInfo(out infoCollection, out errorMessage);

            lock (this)
            {
                this.State = EPop3ClientState.Awaiting;
            }
            return(flag);
        }
예제 #9
0
        // ExStart:DetectingNewMessages
        public static void Run()
        {
            try
            {
                // Connect to the POP3 mail server and check messages.
                Pop3Client pop3Client = new Pop3Client("pop.domain.com", 993, "username", "password");

                // List all the messages
                Pop3MessageInfoCollection msgList = pop3Client.ListMessages();
                foreach (Pop3MessageInfo msgInfo in msgList)
                {
                    // Get the POP3 message's unique ID
                    string strUniqueID = msgInfo.UniqueId;

                    // Search your local database or data store on the unique ID. If a match is found, that means it's already downloaded. Otherwise download and save it.
                    if (SearchPop3MsgInLocalDB(strUniqueID) == true)
                    {
                        // The message is already in the database. Nothing to do with this message. Go to next message.
                    }
                    else
                    {
                        // Save the message
                        SavePop3MsgInLocalDB(msgInfo);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
예제 #10
0
        protected virtual bool _TryGetMessagesInfo(out Pop3MessageInfoCollection infoCollection, out string errorMessage)
        {
            infoCollection = new Pop3MessageInfoCollection();
            errorMessage   = "";
            LIST         command  = new LIST();
            Pop3Response response = this.DoCommand(command);

            if (response.Type == EPop3ResponseType.OK)
            {
                infoCollection = command.Messages;
            }
            else
            {
                errorMessage = response.Message;
            }
            return(true);
        }
예제 #11
0
        private void btnRun_Click(object sender, EventArgs e)
        {
            // Create a POP3 client
            Pop3Client client = new Pop3Client();

            client.Host      = this.HostInput.Text;
            client.Username  = this.Username.Text;
            client.Password  = this.Password.Text;
            client.Port      = int.Parse(this.PortInput.Text);
            client.EnableSsl = true;
            client.Connect();
            Pop3MessageInfoCollection msgs = client.GetAllMessages();

            for (int i = 0; i < msgs.Count; i++)
            {
                MessageBox.Show(string.Format("SequenceNumber:{0};Size:{1};UniqueId:{2}", msgs[i].SequenceNumber, msgs[i].Size, msgs[i].UniqueId));
            }
        }
예제 #12
0
 /// <summary>
 /// Gets the mailbox statistics.
 /// </summary>
 /// <param name="mailbox">The mailbox.</param>
 /// <param name="response">The response.</param>
 /// <param name="statistics">The statistics.</param>
 /// <returns>The response type.</returns>
 protected override CommandResponseType StatisticsCommand(Mailbox mailbox, out string response, out IReadOnlyList <StatisticInfo> statistics)
 {
     try
     {
         uint count = _client.GetStatistic().CountMessages;
         IOrderedEnumerable <Pop3MessageUIDInfo> serverUids = _client.GetAllUIDMessages().OrderByDescending(o => o.SerialNumber);
         Pop3MessageInfoCollection serverSizes = _client.GetMessagesInfo();
         response    = string.Empty;
         statistics  = serverUids.Join(serverSizes, u => u.SerialNumber, s => s.Number, (u, s) => new StatisticInfo(u.UniqueNumber, u.SerialNumber, s.Size, null)).OrderByDescending(o => o.SerialNumber).ToList();
         _statistics = statistics;
         return(CommandResponseType.Ok);
     }
     catch (Exception ex)
     {
         response   = ex.ToString();
         statistics = new List <StatisticInfo>();
         return(CommandResponseType.Bad);
     }
 }
예제 #13
0
        public override int ListMessagesInFolder(ref GridView gridView, string folderUri, string searchText)
        {
            try
            {
                Email.MailQuery mQuery       = Common.GetMailQuery(searchText);
                List <Message>  messagesList = new List <Message>();

                Pop3MessageInfoCollection msgCollection = null;
                if (mQuery == null)
                {
                    msgCollection = client.ListMessages();
                }
                else
                {
                    msgCollection = client.ListMessages(mQuery);
                }
                int messageCount = 1;
                foreach (Pop3MessageInfo msgInfo in msgCollection)
                {
                    if (messageCount > Common.MaxNumberOfMessages)
                    {
                        break;
                    }
                    //Retrieve the message in a MailMessage class
                    messagesList.Add(new Message
                                         (msgInfo.UniqueId.ToString(),
                                         Common.FormatDate(msgInfo.Date),
                                         Common.FormatSubject(msgInfo.Subject),
                                         Common.FormatSender(msgInfo.From)
                                         ));
                    messageCount++;
                }

                gridView.DataSource = messagesList;
                gridView.DataBind();

                return(messagesList.Count);
            }
            catch (Exception) { }

            return(0);
        }
예제 #14
0
        public static void Run()
        {
            // Connect and log in to POP3
            const string host     = "host";
            const int    port     = 110;
            const string username = "******";
            const string password = "******";
            Pop3Client   client   = new Pop3Client(host, port, username, password);

            try
            {
                MailQueryBuilder builder = new MailQueryBuilder();

                // ExStart:CombineQueriesWithAND
                // Emails from specific host, get all emails that arrived before today and all emails that arrived since 7 days ago
                builder.From.Contains("SpecificHost.com");
                builder.InternalDate.Before(DateTime.Now);
                builder.InternalDate.Since(DateTime.Now.AddDays(-7));
                // ExEnd:CombineQueriesWithAND

                // Build the query and Get list of messages
                MailQuery query = builder.GetQuery();
                Pop3MessageInfoCollection messages = client.ListMessages(query);
                Console.WriteLine("Pop3: " + messages.Count + " message(s) found.");

                builder = new MailQueryBuilder();

                // ExStart:CombiningQueriesWithOR
                // Specify OR condition
                builder.Or(builder.Subject.Contains("test"), builder.From.Contains("*****@*****.**"));
                // ExEnd:CombiningQueriesWithOR

                // Build the query and Get list of messages
                query    = builder.GetQuery();
                messages = client.ListMessages(query);
                Console.WriteLine("Pop3: " + messages.Count + " message(s) found.");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
예제 #15
0
        public static void Run()
        {
            // ExStart:FilterMessagesFromPOP3Mailbox
            // Connect and log in to POP3
            const string host     = "host";
            const int    port     = 110;
            const string username = "******";
            const string password = "******";
            Pop3Client   client   = new Pop3Client(host, port, username, password);

            // Set conditions, Subject contains "Newsletter", Emails that arrived today
            MailQueryBuilder builder = new MailQueryBuilder();

            builder.Subject.Contains("Newsletter");
            builder.InternalDate.On(DateTime.Now);
            // Build the query and Get list of messages
            MailQuery query = builder.GetQuery();
            Pop3MessageInfoCollection messages = client.ListMessages(query);

            Console.WriteLine("Pop3: " + messages.Count + " message(s) found.");
            // ExEnd:FilterMessagesFromPOP3Mailbox
        }
        public static void Run()
        {
            // Connect and log in to POP3
            const string host     = "host";
            const int    port     = 110;
            const string username = "******";
            const string password = "******";
            Pop3Client   client   = new Pop3Client(host, port, username, password);

            try
            {
                // ExStart:ApplyCaseSensitiveFilters
                // IgnoreCase is True
                MailQueryBuilder builder1 = new MailQueryBuilder();
                builder1.From.Contains("tesT", true);
                MailQuery query1 = builder1.GetQuery();
                Pop3MessageInfoCollection messageInfoCol1 = client.ListMessages(query1);
                // ExEnd:ApplyCaseSensitiveFilters
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
예제 #17
0
        public static void Run()
        {
            // Connect and log in to POP3
            const string host     = "host";
            const int    port     = 110;
            const string username = "******";
            const string password = "******";
            Pop3Client   client   = new Pop3Client(host, port, username, password);

            try
            {
                // ExStart:GetEmailsWithTodayDate
                // Emails that arrived today
                MailQueryBuilder builder = new MailQueryBuilder();
                builder.InternalDate.On(DateTime.Now);
                // ExEnd:GetEmailsWithTodayDate

                // Build the query and Get list of messages
                MailQuery query = builder.GetQuery();
                Pop3MessageInfoCollection messages = client.ListMessages(query);
                Console.WriteLine("Pop3: " + messages.Count + " message(s) found.");

                builder = new MailQueryBuilder();

                // ExStart:GetEmailsOverDateRange
                // Emails that arrived in last 7 days
                builder.InternalDate.Before(DateTime.Now);
                builder.InternalDate.Since(DateTime.Now.AddDays(-7));
                // ExEnd:GetEmailsOverDateRange

                // Build the query and Get list of messages
                query    = builder.GetQuery();
                messages = client.ListMessages(query);
                Console.WriteLine("Pop3: " + messages.Count + " message(s) found.");

                builder = new MailQueryBuilder();

                // ExStart:GetSpecificSenderEmails
                // Get emails from specific sender
                builder.From.Contains("[email protected]");
                // ExEnd:GetSpecificSenderEmails

                // Build the query and Get list of messages
                query    = builder.GetQuery();
                messages = client.ListMessages(query);
                Console.WriteLine("Pop3: " + messages.Count + " message(s) found.");

                builder = new MailQueryBuilder();

                // ExStart:GetSpecificDomainEmails
                // Get emails from specific domain
                builder.From.Contains("SpecificHost.com");
                // ExEnd:GetSpecificDomainEmails

                // Build the query and Get list of messages
                query    = builder.GetQuery();
                messages = client.ListMessages(query);
                Console.WriteLine("Pop3: " + messages.Count + " message(s) found.");

                builder = new MailQueryBuilder();

                // ExStart:GetSpecificRecipientEmails
                // Get emails sent to specific recipient
                builder.To.Contains("recipient");
                // ExEnd:GetSpecificRecipientEmails

                // Build the query and Get list of messages
                query    = builder.GetQuery();
                messages = client.ListMessages(query);
                Console.WriteLine("Pop3: " + messages.Count + " message(s) found.");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }