概述
By Rohit Joshi
Download demo project - 243 Kb
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>rn
Logout
: Logout and close the socket.<COMMAND_PREFIX> LOGOUTrn
SelectFolder
: It selects the folder. It requires folder name as parameter.<COMMAND_PREFIX> SELECT <FOLDER>rn
ExamineFolder
: It is similar toSelectFolder
, but it does examine.<COMMAND_PREFIX> EXAMINE <FOLDER>rn
GetQuota
: Get the quota of the mailbox.<COMMAND_PREFIX> GETQUOTAROOT <FOLDER>rn
SearchMessage
: You can search the messages. It will return the UID of messages. E.g., From rjoshi.<COMMAND_PREFIX> SEARCH <SEARCH STRING>rn
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 theXmlTextWriter
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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors may to use can be found here
About the Author
Rohit Joshi | 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.
|
最后
以上就是直率芹菜为你收集整理的IMAP Client library using C# 的全部内容,希望文章能够帮你解决IMAP Client library using C# 所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复