I have tried this on C# using open source project called "Koolwired.Imap" on sourceforge.
It was OK when downloading mails, but for attachments it is only listing the file name of the attachment. Is there anyone who has tried this?
If not is there any other better free library which can do the same (I need a free/open source solution for this, because I am doing this for my campus project)
ImapConnect connection = new ImapConnect("imap.gmail.com", 993, true);
ImapCommand command = new ImapCommand(connection);
ImapAuthenticate auth = new ImapAuthenticate(connection, "[email protected]", "bigdick123");
connection.Open();
auth.Login();
string htmlbody = "";
ImapMailbox mailbox = command.Select("INBOX");
mailbox = command.Fetch(mailbox);
int mailCount = mailbox.Messages.Count;
for (int i = 0; i < mailCount ; i++)
{
ImapMailboxMessage msg = mailbox.Messages[mailCount - 1];
msg = command.FetchBodyStructure(msg);
msg.BodyParts[0].ContentEncoding = BodyPartEncoding.NONE;
msg = command.FetchBodyPart(msg, msg.HTML);
foreach (ImapMessageBodyPart a in msg.BodyParts)
{
if (a.Data != null)
{
string fileName = "";
if (a.Attachment) fileName = ParseFileName(a.Disposition);
string mimeType = a.ContentType.MediaType.ToLower();
a.ContentEncoding = BodyPartEncoding.UTF7;
htmlbody = a.Data;
}
}
}
auth.Logout();
connection.Close();