0

The line of listBox1.Items.Add(from + ": " + x.Subject); Is what is not returning a desired result, it adds ": " instead of "FirstNameLastName: Subject title"

https://imapx.codeplex.com/wikipage?title=Sample%20code%20for%20get%20messages%20from%20your%20inbox

and https://imapx.codeplex.com/

    List<Task> m = new List<Task>();
    private async void cmdLogin_Click(object sender, EventArgs e)
    {
        bool result = imapMail.Connection();
        if (result)
        {
            result = imapMail.LogIn(email, password);
            if (result)
            {
                var messes = imapMail.Folders[inbox].Messages;
                foreach (var x in messes)
                {
                    string from = "";
                    foreach (var addresses in x.From)
                    {
                        from = addresses.DisplayName;
                    }
                    listBox1.Items.Add(from + ": " + x.Subject);
                }
                foreach (ImapX.Message msgs in imapMail.Folders[inbox].Messages)
                {
                    m.Add(new Task(new Action(() => msgs.Process())));
                }
                await Task.WhenAll(m);

            }
            else { this.Text = "failed login"; }
        }
        else { this.Text = "Failed connection"; }
    }
}

this isn't returning anything besides a colon, it should be returning a Display Name: Message Subject

ploxtic
  • 273
  • 3
  • 4
  • 20
  • possible duplicate of [Cannot implicitly convert type 'int' to '...Tasks'](http://stackoverflow.com/questions/15462004/cannot-implicitly-convert-type-int-to-tasksint) – John Saunders Mar 18 '13 at 18:33
  • Please don't post the same question just because you're not getting a response. The response will be to close as duplicate. – John Saunders Mar 18 '13 at 18:34
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". Also, unlike forum sites, we don't use "Thanks", or "Any help appreciated", or signatures on [so]. See "[Should 'Hi', 'thanks,' taglines, and salutations be removed from posts?](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be-removed-from-posts). – John Saunders Mar 18 '13 at 18:39
  • has nothing to do with the task though, so take that out. – ploxtic Mar 18 '13 at 18:41

1 Answers1

0

Before you can retrieve the message details (like "from", "subject", etc.), you first need to call Process() on the message. If you look at the source code for ImapX, you'll see that Process() involves a server call to the IMAP server, to download the message data.

It looks like you are trying retrieving the From address BEFORE you are calling Process(), and that will return an empty string. You need to change the order - call Process() first, and only afterwards can you check the message details.

See the code below. I haven't tested this yet.

List<Task> m = new List<Task>();
private async void cmdLogin_Click(object sender, EventArgs e)
{
    bool result = imapMail.Connection();
    if (result)
    {
        result = imapMail.LogIn(email, password);
        if (result)
        {
            foreach (ImapX.Message msgs in imapMail.Folders[inbox].Messages)
            {
                m.Add(new Task(new Action(() => msgs.Process())));
            }
            await Task.WhenAll(m);

            var messes = imapMail.Folders[inbox].Messages;
            foreach (var x in messes)
            {
                string from = "";
                foreach (var addresses in x.From)
                {
                    from = addresses.DisplayName;
                }
                listBox1.Items.Add(from + ": " + x.Subject);
            }
        }
        else { this.Text = "failed login"; }
    }
    else { this.Text = "Failed connection"; }
}