This project is read-only.

How to display a message?

Topics: Issues
Mar 3, 2014 at 12:48 PM
Hello. I apologize for my English.
How to display a message on the screen? And how to find a particular message. For example, under the name of the letter, the sender (... @
I'm very tired. I can not understand.
    public partial class Form1 : Form

        public Form1()

        private void conn_Click(object sender, EventArgs e)

        private void getm_DoWork(object sender, DoWorkEventArgs e)
            var client = new ImapClient("", true);

            if (client.Connect())

                if (client.Login(login.Text, pass.Text))
                    MessageBox.Show("bad login!");
                MessageBox.Show("not connected!");
            ImapX.Collections.FolderCollection folders = client.Folders;
            client.Behavior.AutoPopulateFolderMessages = true;
            foreach (ImapX.Message m in client.Folders.Inbox.Messages)
                //addrow(Convert.ToString(m.From), Convert.ToString(m.Sender), Convert.ToString(m.Subject));

        private int addrow(string adress, string name, string subj)
            int i = 0;
            Invoke(new Action(() => i = listView1.Items.Add(adress).Index));
            Invoke(new Action(() => listView1.Items[i].SubItems.Add(name)));
            Invoke(new Action(() => listView1.Items[i].SubItems.Add(subj)));
            return i;

Mar 3, 2014 at 1:58 PM
Hi jallvar,

first of all, feel free to contact me in Russian through mail:

A small remark on your code

I recommend setting client.Behavior.AutoPopulateFolderMessages to true before connecting. This will keep your code clean, doing all major configuration of the client in one place.

Searching for messages

The general information on searching for messages can be found in the documentation. If you like to perform a search by the subject of the message, or a specific sender, use the following approach:
// Search all messages containing "" in the FROM field
var messages = client.Folders.Inbox.Search("FROM \"\"");

// Search all messages containing "Test" in subject
var messages = client.Folders.Inbox.Search("SUBJECT \"Test\"");
A full list of available criterias can be found in the specification.
If you like to perform a query with non-ascii characters (e.g subject in russian), use this thread for reference.
In case you are planning to use the library with the servers of, please consider that their server implementation is not complete and doesn't allow the use of various search criterias.

Displaying messages

For displaying a message in a Windows Forms project you can use a WebBrowser control. The sample application you can find in the downloads section does the same. This is the approximate code:
// Getting the available body (html is priority, text used if no html body available)
string body = message.Body.HasHtml ? message.Body.Html : message.Body.Text;

// Open a new document in WebBrowser

// Writing the message body to the document
webBrowser1.Document.Write(message.Body.HasHtml ? body : body.Replace(Environment.NewLine, "<br />"));
Best regards,

Mar 3, 2014 at 2:01 PM
thanks )))