Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# mail retrieve library

using System;
using System.Net;
using System.Threading;

using MailKit.Net.Imap;
using MailKit.Search;
using MailKit;
using MimeKit;

namespace TestClient {
    class Program
    {
        public static void Main (string[] args)
        {
            using (var client = new ImapClient ()) {
                using (var cancel = new CancellationTokenSource ()) {
                    client.Connect ("imap.gmail.com", 993, true, cancel.Token);

                    // If you want to disable an authentication mechanism,
                    // you can do so by removing the mechanism like this:
                    client.AuthenticationMechanisms.Remove ("XOAUTH");

                    client.Authenticate ("joey", "password", cancel.Token);

                    // The Inbox folder is always available...
                    var inbox = client.Inbox;
                    inbox.Open (FolderAccess.ReadOnly, cancel.Token);

                    Console.WriteLine ("Total messages: {0}", inbox.Count);
                    Console.WriteLine ("Recent messages: {0}", inbox.Recent);

                    // download each message based on the message index
                    for (int i = 0; i < inbox.Count; i++) {
                        var message = inbox.GetMessage (i, cancel.Token);
                        Console.WriteLine ("Subject: {0}", message.Subject);
                    }

                    // let's try searching for some messages...
                    var query = SearchQuery.DeliveredAfter (DateTime.Parse ("2013-01-12"))
                        .And (SearchQuery.SubjectContains ("MailKit"))
                        .And (SearchQuery.Seen);

                    foreach (var uid in inbox.Search (query, cancel.Token)) {
                        var message = inbox.GetMessage (uid, cancel.Token);
                        Console.WriteLine ("[match] {0}: {1}", uid, message.Subject);
                    }

                    client.Disconnect (true, cancel.Token);
                }
            }
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: how to declare two int variables in only one line c# 
Csharp :: conevrt list to pipe separated string c# 
Csharp :: asp.net list find 
Csharp :: how to save checkbox value in database in c# 
Csharp :: c# office interop copy slide to another pppt 
Csharp :: unity gamemanager instance not set to an instance of an object 
Csharp :: wetter warendorf 
Csharp :: c# lernen kostenlos 
Csharp :: commandline to open outlook minimized 
Csharp :: vb.net how insert event inside an event 
Csharp :: c# convert datatable to csv 
Csharp :: custom vscode snippet 
Csharp :: Maximum Sum of Non-Adjacent Elements 
Csharp :: check list exist in list c# if matches any 
Csharp :: unity in app review 
Csharp :: unity find disabled gameobject 
Csharp :: compile c# file in terminal 
Csharp :: c# get regedit value 
Csharp :: how to scale text from center in unity 
Csharp :: webbrowser control feature_browser_emulation compatible 
Csharp :: c# switch statement 
Html :: link css to html 
Html :: multipart form 
Html :: link css html 
Html :: python jupyter markdown color 
Html :: html input type file accept text and word files 
Html :: How to display Base64 images in HTML? 
Html :: gender selection in html 
Html :: justify content 
Html :: alternative image in img tag 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =