Click here to Skip to main content
15,887,945 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello every one im working on a project now i have issue. im using s22.imap library now i can gent first unseen mail and show in text box
i want to get first 10 or all unseen email in data grid view is it possible please help how can i do this ?

What I have tried:

C#
using (ImapClient client = new ImapClient(hostname, 993, username, password, AuthMethod.Login, true))
            {

                IEnumerable<uint> uids = client.Search(SearchCondition.Unseen());

                // Fetch the mail headers of the first message and print it's subject line.
                if (uids.Count() > 0)
                {
                    MailMessage msg = client.GetMessage(uids.First(), FetchOptions.TextOnly);

                    s= ("Subject: " + msg.Subject);
                    textBox1.Text = s;
                    d=("From:" + msg.From);
                    textBox2.Text = d;
                    
                    b = ("Body: " + msg.Body);
                    textBox3.Text = b;
                    
                }</uint>
Posted
Updated 9-May-16 6:47am
v2

1 solution

Use
var firstTen = client.GetMessages(uids.Take(10), FetchOptions.TextOnly)
foreach(MailMessage msg in firstTen)
{
    // ... your code here
}

(untested)
 
Share this answer
 
Comments
Mehran Shafqat 10-May-16 4:55am    
i have no idea now what can i do in loop ? :( how can i get first email in data grid where first column take subject second sender and 3rd body message how can i achieve this sir for each email ?
jonhy05 10-May-16 10:23am    
Are you showing it in a gridview? Or in text boxes?
Mehran Shafqat 11-May-16 16:08pm    
sir i done in text box but in text simple one email can show now i want the all unseen email show in data grid view for e.g first email in first row where the column take subject second one sender name third one email
and then second row show 2nd unseen email and 3rd one 3rd email like please help me if you have any idea how can i achieve this ?
jonhy05 16-May-16 16:04pm    
<pre lang="c#">dataGridView1.DataSource = firstTen</pre>
Or:
<pre lang="c#">
this.bindingSource1.DataSource = new BindingList<cliente>();
DataGridViewColumn column1 = new DataGridViewTextBoxColumn();
column1.HeaderText = "Email Sender";
column1.DataPropertyName = "Sender";
DataGridViewColumn column2 = new DataGridViewTextBoxColumn();
column2.HeaderText = "Email Subject";
column2.DataPropertyName = "Subject";
DataGridViewColumn column3 = new DataGridViewTextBoxColumn();
column3.HeaderText = "Email Body";
column3.DataPropertyName = "Body";

dataGridView1.Columns.Add(column1);
dataGridView1.Columns.Add(column2);
dataGridView1.Columns.Add(column3);
dataGridView1.DataSource = this.bindingSource1;
</pre>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900