public void Scan() { Chilkat.StringArray saUidls = null; // Get the complete list of UIDLs saUidls = mailMan.GetUidls(); if (saUidls == null) { return; } // Get the 10 most recent UIDLs // The 1st email is the oldest, the last email is the newest // (usually) int i; int n; int startIdx; int bundleSize = 3; n = saUidls.Count; startIdx = n > bundleSize ? n - bundleSize : 0; Chilkat.StringArray saUidls2 = new Chilkat.StringArray(); for (i = startIdx; i <= n - 1; i++) { saUidls2.Append(saUidls.GetString(i)); } // Download in full the 10 most recent emails: Chilkat.EmailBundle bundle = null; bundle = mailMan.FetchMultiple(saUidls2); if (bundle == null) { Console.WriteLine(mailMan.LastErrorText); return; } Chilkat.Email email = null; for (i = 0; i <= bundle.MessageCount - 1; i++) { email = bundle.GetEmail(i); Console.WriteLine(email.From); Console.WriteLine(email.Subject); Console.WriteLine("----"); if (email == null) { Console.WriteLine(mailMan.LastErrorText); return; } if (ValidateCommand(email)) { ProcessValidEmail(email); } else { ProcessInvalidEmail(email); } } }
public IList <Email> GetAllMails(string fromEmailID) { IList <Email> emails = new List <Email>(); using (Chilkat.Imap imap = new Imap()) { if (imap.UnlockComponent("EASYDAIMAPMAILQ_vcyhVCXs2N0G")) { if (connectToIMAPMailServer(imap)) { Chilkat.MessageSet messageSet = null; bool fetchUids = false; // Select an IMAP mailbox success = imap.SelectMailbox("Inbox"); if (success != true) { //Debug.WriteLine(imap.LastErrorText); return(null); } messageSet = imap.Search(string.Format("FROM {0}", fromEmailID), fetchUids); /*if (success != true) * { * Logger.LogDebug(imap.LastErrorText); * return null; * }*/ //if (imap.LastMethodSuccess == false) //{ // //Debug.WriteLine(imap.LastErrorText); // return null; //} //bool bUid = false; //string mimeStr; //int n = imap.NumMessages; Chilkat.EmailBundle bundle = null; bundle = imap.FetchBundle(messageSet); int i = 0; while (i < bundle.MessageCount) { Chilkat.Email email = null; email = bundle.GetEmail(i); emails.Add(email); //DataRow drEmail = dtEmails.NewRow(); //drEmail["From"] = email.From; //drEmail["FromAddress"] = email.FromAddress; //drEmail["FromName"] = email.FromName; ////drEmail["To"] = email.; //drEmail["LocalDate"] = email.LocalDate; //drEmail["Subject"] = email.Subject; //drEmail["Body"] = email.Body; //drEmail["NumAttachedMessages"] = email.NumAttachments; //drEmail["Size"] = email.Size; //drEmail["NumDaysOld"] = email.NumDaysOld; //dtEmails.Rows.Add(drEmail); i = i + 1; } // An alternative is to download each email in the form of an // email object, like this: //Chilkat.Email email = null; //for (int i = 1; i <= n; i++) //{ // // Download the email by sequence number. // email = imap.FetchSingle(i, bUid); // emails.Add(email); // if (i > 100) // break; // // ... your application may process the email object... //} // Disconnect from the IMAP server. success = imap.Disconnect(); //bool fetchUids = false; //string fetchEmailCriteria = "ALL"; //Chilkat.MessageSet messageSet = new MessageSet(); //messageSet = imap.Search(fetchEmailCriteria, fetchUids); //if (messageSet == null) //{ // Logger.LogDebug("Unable to fetch email from mail server."); // return null; //} //EmailBundle emailBundle = imap.FetchBundle(messageSet); //if (emailBundle == null) //{ // Logger.LogDebug("Unable to fetch email from mail server."); // return null; //} //for (int i = 0; i <= emailBundle.MessageCount -1;i++) //{ // emailBundle.SortByDate(true); // Email email = emailBundle.GetEmail(i); // emails.Add(email); //} } } } return(emails); }