I tried this in C # using an open source project called "Koolwired.Imap" on sourceforge.
This was normal when downloading emails, but for attachments this is just a list of the attachment file name. Has anyone tried this?
If there is no other best free library that can do the same (I need a free / open source solution for this because I do this for my project on campus)
ImapConnect connection = new ImapConnect("imap.gmail.com", 993, true); ImapCommand command = new ImapCommand(connection); ImapAuthenticate auth = new ImapAuthenticate(connection, "<username>@gmail.com", "<password>"); 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();
source share