gurbax
  • gurbax
  • 50.25% (Neutral)
  • Newbie Topic Starter
10 years ago
I am using below code to get the emails


        oClient.Connect(oServer);
       
        MailInfo[] infos = oClient.GetMailInfos();

        int count = infos.Length;

        for (int i = 0; i < 100; i++)
        {
            MailInfo info = infos[i];
            if (oUIDLManager.FindUIDL(oServer, info.UIDL) != null)
            {
                continue;
            }

           
            Mail oMail = oClient.GetMail(info);
           oMail.SaveAs("fileName", true);

  
           }


but the MailInfo[] infos = oClient.GetMailInfos(); retreive the information of all the emails, so it is taking time to load. i have more than 9000 emails in the mail box.

But I need top 100 emails only each time.


SO can you please provide me any idea how can i get info of only 100 emails and also get top 100 emails according to date?
ivan
  • ivan
  • 100% (Exalted)
  • Administration
10 years ago
Base on IMAP4 protocol, you can do it like this:

http://www.emailarchitect.net/eagetmail/sdk/?ct=mailclient_getmailinfosparam 

First of all, you can get total email count by

http://www.emailarchitect.net/eagetmail/sdk/?ct=mailclient_getmailcount 

then you can specify GetMailInfosOptionType.SeqRange

for example:

oClient.GetMailInfosParam.GetMailInfosOptions = GetMailInfosOptionType.SeqRange;
oClient.GetMailInfosParam.SeqRange = "1:100";

MailInfo[] infos = oClient.GetMailInfos();

If you use EWS or WebDAV protocol, you can only specify a date time range.


        oClient.GetMailInfosParam.GetMailInfosOptions |= GetMailInfosOptionType.DateRange;
        oClient.GetMailInfosParam.GetMailInfosOptions |= GetMailInfosOptionType.OrderByDateTime;

        oClient.GetMailInfosParam.DateRange.SINCE = System.DateTime.Now.AddDays(-1);
        oClient.GetMailInfosParam.DateRange.BEFORE = System.DateTime.Now.AddDays(1);

ileandros
10 years ago
How can I get only the latest for example 10 emails?
I tried something like this but didn't do the trick.
public static void POP3ReadMails()
        {
            string curpath = Directory.GetCurrentDirectory();
            string mailbox = String.Format("{0}\\inbox", curpath);

            if (!Directory.Exists(mailbox))
            {
                Directory.CreateDirectory(mailbox);
            }
            Console.WriteLine("Creating path: " + mailbox);
            MailServer oServer = new MailServer("pop3.live.com",
                        "ID@hotmail.com", "pass", ServerProtocol.Pop3);
            MailClient oClient = new MailClient("TryIt");
            oServer.SSLConnection = true;
            oServer.Port = 995;
            oClient.GetMailInfosParam.GetMailInfosOptions = GetMailInfosOptionType.SeqRange;
            oClient.GetMailInfosParam.SeqRange = "10";

            try
            {
                oClient.Connect(oServer);
                MailInfo[] infos = oClient.GetMailInfos();
                Console.WriteLine(infos.Length);
                for (int i = 0; i < 5; i++)
                {
                    MailInfo info = infos[i];
                    Console.WriteLine("Index: {0}; Size: {1}; UIDL: {2}",
                        info.Index, info.Size, info.UIDL);
                    Mail oMail = oClient.GetMail(info);
                    oMail.SaveAs(mailbox + "\\" + info.UIDL + ".eml", true);
                    oClient.Delete(info);
                }

                oClient.Quit();
            }
            catch (Exception ep)
            {
                Console.WriteLine(ep.Message);
            }
        }
Any ideas?
ivan
  • ivan
  • 100% (Exalted)
  • Administration
10 years ago
Hi, you need to use IMAP4 protocol.


Console.WriteLine("Creating path: " + mailbox);
MailServer oServer = new MailServer("imap-mail.outlook.com",
"ID@hotmail.com", "pass", ServerProtocol.Imap4);
MailClient oClient = new MailClient("TryIt");
oServer.SSLConnection = true;
oServer.Port = 993;
oClient.GetMailInfosParam.GetMailInfosOptions = GetMailInfosOptionType.SeqRange;
oClient.GetMailInfosParam.SeqRange = "1:10";

ivan
  • ivan
  • 100% (Exalted)
  • Administration
10 years ago
If you want to get latest 10 emails, please try this:


public static void POP3ReadMails()
{
string curpath = Directory.GetCurrentDirectory();
string mailbox = String.Format("{0}\\inbox", curpath);

if (!Directory.Exists(mailbox))
{
Directory.CreateDirectory(mailbox);
}
Console.WriteLine("Creating path: " + mailbox);
MailServer oServer = new MailServer("imap-mail.outlook.com",
"ID@hotmail.com", "pass", ServerProtocol.Imap4);
MailClient oClient = new MailClient("TryIt");
oServer.SSLConnection = true;
oServer.Port = 993;


try
{
oClient.Connect(oServer);

int totalcount = oClient.GetMailCount();

string range = "";
if( totalcount > 10 )
{
   range = String.Fromat( "{0}:{1}", totalcount - 10, totalcount );
}
else
{
   range = String.Fromat( "*:{0}", totalcount );
}

oClient.GetMailInfosParam.GetMailInfosOptions = GetMailInfosOptionType.SeqRange;
oClient.GetMailInfosParam.SeqRange = range;

if( totalcount > 0 )
{
MailInfo[] infos = oClient.GetMailInfos();
Console.WriteLine(infos.Length);
for (int i = 0; i < infos.Length; i++)
{
MailInfo info = infos[i];
Console.WriteLine("Index: {0}; Size: {1}; UIDL: {2}",
info.Index, info.Size, info.UIDL);
Mail oMail = oClient.GetMail(info);
oMail.SaveAs(mailbox + "\\" + info.UIDL + ".eml", true);
oClient.Delete(info);
}
}
oClient.Quit();
}
catch (Exception ep)
{
Console.WriteLine(ep.Message);
}
}

EXPLORE TUTORIALS

© All Rights Reserved, AIFEI Software Limited & AdminSystem Software Limited.