Hi Aspose,
Is there anyway to check the a particular email message existence in the server before download the email (may be using unique url) by MAPI, POP & IMAP protocols?
Hi,
Thanks for writing to Aspose.Email support team.
Aspose provides features for extracting mail information without downloading it. For exchange servers, ExchangeMessageInfoCollection and ExchangeAttachmentInfoCollection can be used to retrieve the actual mail information in advance. For Pop3 servers you may please use Pop3MessageInfoCollection and MessageInfo for MapiMessages.
Following sample code demonstrate all these features. You may please give it a try and let us know your feedback.
//Imap
ImapClient client1 = GetPostecertImapClient();
client1.Connect();
foreach (ImapFolderInfo info in client1.ListFolders())
{
Console.WriteLine(info.Name);
}
client1.SelectFolder(ImapFolderInfo.InBox);
ImapMessageInfoCollection list = client1.ListMessages();
int i = 0;
foreach (ImapMessageInfo msgInfo in list)
{
LogFile(i.ToString() + “.Subj:” + msgInfo.Subject);
LogFile(i.ToString() + “.Sender:” + msgInfo.Sender);
LogFile(i.ToString() + “.UID:” + msgInfo.UniqueId);
i++;
}
client1.Disconnect();
//Exchange
const string mailboxUri = “https:[//MailboxUrl.asmx](https://mailboxurl.asmx/)”;
const string domain = “”;
const string username = “user”;
const string password = “pwd”;
NetworkCredential credential = new NetworkCredential(username, password, domain);
IEWSClient client2 = new ExchangeWebServiceClient(mailboxUri, credential);
ExchangeMessageInfoCollection coll = client2.ListMessages(“Inbox”);
ExchangeAttachmentInfoCollection attchColl = coll[0].Attachments;
int iAttachSize = attchColl[0].Size;
//Pop3
Aspose.Email.Pop3.Pop3Client client3;
client3 = new Aspose.Email.Pop3.Pop3Client();
// basic setings (required)
client3.Host = “[pop.gmail.com](http://pop.gmail.com/)”;
client3.Username = "user@gmail.com";
client3.Password = “password”;
client3.Port = 995; // set SSL port
// Settings required for SSL enabled Pop3 servers
client3.SecurityMode = Aspose.Email.Pop3.Pop3SslSecurityMode.Implicit; // set implicit security mode
client3.EnableSsl = true; // enable SSL
client3.Connect(); // establish a connection
client3.Login(); // login
Pop3MessageInfoCollection infos = client3.ListMessages();
// iterate through the messages
foreach (Aspose.Email.Pop3.Pop3MessageInfo info in infos)
{
Console.WriteLine(info.Subject);
Console.WriteLine(info.Date);
}
//Mapi
PersonalStorage pst2 = PersonalStorage.FromFile(“OutputPst.pst”);
FolderInfo folderInfo = pst2.GetPredefinedFolder(StandardIpmFolder.Inbox);
MessageInfoCollection messageInfoCollection = folderInfo.GetContents();
foreach (MessageInfo messageInfo in messageInfoCollection)
{
MapiMessage mapi = pst2.ExtractMessage(messageInfo);
MailMessageInterpretor mi = MailMessageInterpretorFactory.Instance.GetIntepretor(mapi.MessageClass);
MailMessage mailMsg = mi.Interpret(mapi);
}
You may also consider using ExchangeQueryBuilder for exchange, ImapQueryBuilder for Imap and MailQueryBuilder for Pop3 servers to filter the emails with different criteria.
Please feel free to write us back if you have any query in this regard.
Hi Kashif,
Thank you for your detailed reply. I think I have not clearly explained my requirement.
You think two threads downloads the emails from the same server at same time.
Each thread get the list of emails in the server at begin (client1.ListMessages()) and proceed one by one.
Each thread download the email after downloading it.
So both thread has same email list. If a certain thread try to download an email that already deleted from some other thread. “fetch” function return a exception.
So what I need to do is
Get the email list from the begin as you mention.
Then before download each email I need to check that particular email is still exist in the server.
something like
client1.isEmailExist(msg_info.UniqueUri);
Hi,
Thank you for providing the feedback.
I have analyzed your requirements from the API capabilities point of view with reference from documentation, but I am afraid to share that there is no such method available. I’m not sure if any such feature can be provided as it depends on the protocol capability. But you can add a try catch block to handle the thrown exception as a result of delete operation for the record that doesn’t exist.