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
Rank: Administration
Groups: Administrators
Joined: 11/11/2010(UTC) Posts: 1,153
Thanks: 9 times Was thanked: 55 time(s) in 55 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);
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?
Rank: Administration
Groups: Administrators
Joined: 11/11/2010(UTC) Posts: 1,153
Thanks: 9 times Was thanked: 55 time(s) in 55 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";
Rank: Administration
Groups: Administrators
Joined: 11/11/2010(UTC) Posts: 1,153
Thanks: 9 times Was thanked: 55 time(s) in 55 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
Forum Jump
EmailArchitect Support
Email Component Development
- EASendMail SMTP Component - .NET Version
- EASendMail SMTP Component - Windows Store Apps
- EASendMail SMTP ActiveX Object
- EAGetMail POP3 & IMAP4 Component - .NET Version
- EAGetMail POP3 & IMAP4 ActiveX Object
Exchange Server and IIS SMTP Plugin
- DomanKeys/DKIM for Exchange Server and IIS SMTP
- Disclaimer and S/MIME for Exchange Server and IIS
EmailArchitect Email Server
- EmailArchitect Email Server (General)
- EmailArchitect Email Server Development
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.