Click here to Skip to main content
6,631,404 members and growing! (18,569 online)
Email Password   helpLost your password?
General Programming » Internet / Network » Email     Intermediate License: The Mozilla Public License 1.1 (MPL 1.1)

IMAP Client library using C#

By Rohit Joshi

IMAPLibrary supports the basic IMAP protocol functions to fetch messages from the mailbox.
C#, VC7.NET 1.0, .NET 1.1, WinXPVS.NET2003, Dev
Posted:16 Aug 2004
Updated:13 Jan 2005
Views:194,282
Bookmarked:81 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
33 votes for this article.
Popularity: 6.55 Rating: 4.31 out of 5

1

2
2 votes, 6.3%
3
11 votes, 34.4%
4
19 votes, 59.4%
5

Introduction

The Internet Message Access Protocol (IMAP) allows a client to access and manipulate electronic mail messages on a server. It includes operations for creating, deleting, and renaming mailboxes; checking for new messages; permanently removing messages; setting and clearing flags; [RFC-822] and [MIME-IMB] parsing; searching; and selective fetching of message attributes, texts, and portions thereof. For more information: here.

I have written an IMAP client library which allows basic functionalities like login, select/examine folder, search messages, fetch message (Header, Body), get storage quota, and logout.

This is my first application developed in C#, so don't expect too much in terms of efficiency. It demonstrates the use of sockets, XML writer, and user defined exception handling. Please feel free to modify and use this code.

The attached zip file contains three directories.

IMAP Library: It contains three source files.

  • ImapBase.cs: contains the IMAP commands related to string, and socket related functionality.
  • ImapException.cs: defines the user defined IMAP related error messages.
  • Imap.cs: IMAP client library functions. It has the following public functions:
    • Login: Login to IMAP server. It requires IMAP hostname, port, username, and password.
      <COMMAND_PREFIX> LOGIN <USERID> <PASSWORD>\r\n
    • Logout: Logout and close the socket.
      <COMMAND_PREFIX> LOGOUT\r\n
    • SelectFolder: It selects the folder. It requires folder name as parameter.
      <COMMAND_PREFIX> SELECT <FOLDER>\r\n
    • ExamineFolder: It is similar to SelectFolder, but it does examine.
      <COMMAND_PREFIX> EXAMINE <FOLDER>\r\n
    • GetQuota: Get the quota of the mailbox.
      <COMMAND_PREFIX> GETQUOTAROOT <FOLDER>\r\n
    • SearchMessage: You can search the messages. It will return the UID of messages. E.g., From rjoshi.
      <COMMAND_PREFIX> SEARCH <SEARCH STRING>\r\n
    • FetchMessage: It retrieves the complete message with attachments and writes into an XML file. The XML file will be generated in your current directory with file name as <MessageUID>.xml. You need to pass the XmlTextWriter object, message UID, and flag to fetch body.
      <COMMAND_PREFIX> UID FETCH  <MSG UID> BODY[HEADER]
    • FetchPartBody: Fetch the body for a specific part. It requires message UID, part number as parameter.
    • FetchPartHeader: Fetch the header of message.

Documentation: HTML Documentation for IMAP Library generated using Visual Studio .NET.

IMAP Library test program: The IMAP test program allows users to test the following functionalities.

  • Login
  • Select/Examine folder
  • Search
  • Fetch Message
  • Get Quota
  • Logout

License

This article, along with any associated source code and files, is licensed under The Mozilla Public License 1.1 (MPL 1.1)

About the Author

Rohit Joshi


Member
Rohit Joshi is a software engineer working for a telecom company in USA. He has development expirience using C, C++ ,C#, VoiceXML, ASR, IMAP, LDAP, HTTP, SIP, H323 on unix/linux and platforms.
Occupation: Software Developer
Location: United States United States

Other popular Internet / Network articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 216 (Total in Forum: 216) (Refresh)FirstPrevNext
QuestionError In GMail Pinmembermadaya5:29 16 Nov '09  
GeneralIMAP connect issue [modified] PinmemberShivarudrayya H21:11 5 Nov '09  
GeneralHow to get entire body from the mail message without "=" or junk characters Pinmembermanchu7310:44 4 Nov '09  
GeneralRe: How to get entire body from the mail message without "=" or junk characters PinmemberRohit Joshi7:52 5 Nov '09  
GeneralLogin Failed PinmemberMeetu Choudhary1:22 24 Aug '09  
GeneralRe: Login Failed Pinmember10BRG4:27 26 Aug '09  
GeneralRe: Login Failed PinmemberAtmospherian7:37 26 Aug '09  
GeneralRe: Login Failed Pinmember10BRG7:47 26 Aug '09  
GeneralIs there sample code to download attachment? Pinmembermanchu7318:46 30 Jul '09  
GeneralRe: Is there sample code to download attachment? Pinmembermemotraxtr6:34 31 Jul '09  
GeneralSpecial chars Pinmemberscorpiobra15:41 15 Jul '09  
GeneralRe: Special chars Pinmemberlesnikowski12:45 14 Oct '09  
GeneralMark read in SELECT and EXAMINE Pinmemberscorpiobra14:58 8 Jul '09  
GeneralRe: Mark read in SELECT and EXAMINE Pinmemberscorpiobra7:50 9 Jul '09  
GeneralRe: Mark read in SELECT and EXAMINE PinmemberRohit Joshi12:36 9 Jul '09  
GeneralRe: Mark read in SELECT and EXAMINE Pinmemberscorpiobra3:27 10 Jul '09  
GeneralRe: Mark read in SELECT and EXAMINE PinmemberRohit Joshi4:16 10 Jul '09  
GeneralRe: Mark read in SELECT and EXAMINE Pinmemberscorpiobra4:55 10 Jul '09  
GeneralRe: Mark read in SELECT and EXAMINE PinmemberRohit Joshi6:18 10 Jul '09  
GeneralRe: Mark read in SELECT and EXAMINE Pinmemberscorpiobra7:09 10 Jul '09  
GeneralRe: Mark read in SELECT and EXAMINE PinmemberRohit Joshi8:30 10 Jul '09  
QuestionNot connected to gmail Pinmemberashishshar0:12 12 May '09  
AnswerRe: Not connected to gmail Pinmember10BRG4:04 26 Aug '09  
GeneralWhat is syntax for expunge uid? Pinmembermanchu737:45 11 May '09  
GeneralRe: What is syntax for expunge uid? PinmemberRohit Joshi8:48 11 May '09  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 13 Jan 2005
Editor: Genevieve Sovereign
Copyright 2004 by Rohit Joshi
Everything else Copyright © CodeProject, 1999-2009
Web18 | Advertise on the Code Project