Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
gurbax  
#1 Posted : Tuesday, November 11, 2014 3:59:45 AM(UTC)
gurbax

Rank: Newbie

Groups: Registered
Joined: 11/11/2014(UTC)
Posts: 0

I am using below code to get the emails

Code:

        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?

Edited by moderator Wednesday, January 21, 2015 6:31:06 PM(UTC)  | Reason: better for search

ivan  
#2 Posted : Tuesday, November 11, 2014 4:49:20 PM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,012

Thanks: 9 times
Was thanked: 37 time(s) in 37 post(s)
Base on IMAP4 protocol, you can do it like this:

http://www.emailarchitec...client_getmailinfosparam

First of all, you can get total email count by

http://www.emailarchitec...=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.

Code:

        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  
#3 Posted : Monday, January 19, 2015 3:33:27 PM(UTC)
ileandros

Rank: Newbie

Groups: Registered
Joined: 1/19/2015(UTC)
Posts: 1

How can I get only the latest for example 10 emails?
I tried something like this but didn't do the trick.
Code:
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  
#4 Posted : Monday, January 19, 2015 6:36:01 PM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,012

Thanks: 9 times
Was thanked: 37 time(s) in 37 post(s)
Hi, you need to use IMAP4 protocol.

Code:

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  
#5 Posted : Monday, January 19, 2015 6:44:11 PM(UTC)
ivan

Rank: Administration

Groups: Administrators
Joined: 11/11/2010(UTC)
Posts: 1,012

Thanks: 9 times
Was thanked: 37 time(s) in 37 post(s)
If you want to get latest 10 emails, please try this:

Code:

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);
}
}

Edited by user Monday, January 19, 2015 6:47:21 PM(UTC)  | Reason: Not specified

Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2019, Yet Another Forum.NET
This page was generated in 0.071 seconds.

EXPLORE TUTORIALS

© All Rights Reserved, AdminSystem Software Limited.