How can i list all messages from "sent mail" folder of gmail?

Hi,

I wanted to list all the messages from "Sent Mail" folder of gmail using ImapClient. But it always gives me error that folder doen't exist.

Plz help ??

Hi Majid,


Thank you for considering Aspose.

Please note that “Sent Mail” folder is not present at the root of a Gmail account. It is rather a sub-folder of “[Gmail]” folder. You can confirm this by listing all sub-folders as given below,

C#
var folders = client.ListFolders("[Gmail]");
foreach (var folder in folders)
{
Console.WriteLine(folder.Name);
}

To list all messages from the "Sent Mail" sub-folder, please use the source code as given below,

C#
var client = new Aspose.Email.Imap.ImapClient("imap.gmail.com", "username@gmail.com", "password"); client.Connect(true); client.SelectFolder("[Gmail]/Sent Mail"); var messageInfoCol = client.ListMessages(); foreach (var messageInfo in messageInfoCol) { var SequenceNumber = messageInfo.SequenceNumber; var message = client.FetchMessage(SequenceNumber, true); var subject = message.Subject; Console.WriteLine(subject); }

Hope this helps.
Regards,

Babar,

Thanks for your response.

I have already figured that out and solved the issue.

But I have run into other couple of issues, will you please help me out.

1. I want to create an entry in the sent items folder explicitly. Very similar to that of drafts folder. Is that possible ? If yes can u please send me any code sample ?

Majid,
Software Engineer,
Masterkey Systems.

Hi Majid,

majidkorai:

1. I want to create an entry in the sent items folder explicitly. Very similar to that of drafts folder. Is that possible ? If yes can u please send me any code sample ?


Could you please elaborate your scenario further? By entry do you mean a message or a folder?

Looking forward to your response.
Regards,

by entry i meant a message.

I want to create a message entry in sent mail folder. is it possible ?
I am able to do so while working with exchange API. Now i want to do the same here with gmail api too.

Majid

Hi Majid,

Thank you for the clarification.

Using ImapClient, you can append a message to any folder/sub-folder of your Gmail account. Please check the below source code for your reference,

C#

var client = new Aspose.Email.Imap.ImapClient(“[imap.gmail.com](http://imap.gmail.com/)”, "username@gmail.com", “password”);
client.Connect(true);
var message = new MailMessage();
message.From = "from@domain.com";
message.Subject = “Subject”;
message.Body = “body”;
client.AppendMessage("[Gmail]/Sent Mail", message);

Thanks babar.

It worked.

Hi,

Another issue… :slight_smile:
I want to search the messages from server on the basis of a date.
MailQuery provides me with search on dates.
But still there is an issue with it. It only searches between dates and not time.

With a little research i found that IMAP supports the search between dates and times. It provides two operators “YOUNGER” and “OLDER” for this.

Now my question is this, that can i provide this sort of command in string format to MailQuery ? or is there any other way i can search the messages on the basis of date and time.

Hi Majid,


Please accept my apologies for the delayed response.

I have researched a little on your requirement. I regret to inform you that the current implementation of Aspose.Email for .NET product does not offer any means to include the Time part when building MailQuery to list messages between some specific time intervals (on same day). To enhance our component, I have logged a ticket (NETWORKNET-33240) in our tracking system, and requested the development team to analyse your requirement. As soon as we have made some significant progress, we would be more than happy to update you with the status of correction.

Regards,

Hi Majid,

Thank you for your patience.

It is to brief you on the current status of the ticket NETWORKNET-33240, that we have closed after analyzing the issue in detail.

Please note that Aspose.Email’s MailQuery class uses ‘Search’ command of Internet Message Access Protocol (IMAP). According to [RFC3501](http://tools.ietf.org/html/rfc3501#section-6.4.4) the type date uses only date value disregarding time and timezone. So we can’t filter messages by time with IMAP ‘Search’ command, but in some cases it is possible to filter the search results after IMAP ‘Search’ command has finished.

If you require I can pass on a workaround for your situation.

Regards,