+1 vote

How can I fetch the emails from Gmail Folders like Sent Mail, Drafts etc?

by

1 Answer

0 votes
 
Best answer

To access different IMAP folder than INBOX, you need to use overloaded Imap.Select method which takes FolderInfo or string parameter.

You can use Imap.GetFolders method to obtain all available IMAP folders and CommonFolders class to identify 'system' folders (like Drafts, Sent, Trash).

After that you can use Imap.GetAll, Imap.Search and Imap.GetMessageByUID methods to search and download email messages.

using (Imap imap = new Imap())
{
    imap.ConnectSSL("imap.gmail.com");
    imap.UseBestLogin("user", "password");

    CommonFolders common = new CommonFolders(imap.GetFolders());

    imap.Select(common.Sent);

    List<long> uids = imap.GetAll();

    foreach (long uid in uids)
    {
        IMail email = new MailBuilder()
            .CreateFromEml(imap.GetMessageByUID(uid));
        string subject = email.Subject;
    }
    imap.Close();
}
by (301k points)
im not getting it in java
sir
This is .NET not java.
is there any way to get in java
...