ImapX – free for use .NET library
ImapX is an modern .NET 2.0 library for management of IMAP folders, supports SSL Connection and different IMAP formats, such as Gmail IMAP, AOL IMAP
Here is simple example of usage:
ImapX.ImapClient client = new ImapX.ImapClient("imap.gmail.com", 993, true);
bool result = false;
result = client.Connection();
if (result)
Console.WriteLine("@Connected");
result = client.LogIn(userName, userPassword);
if (result)
{
Console.WriteLine("@Logged in");
}
//Folder Collection
ImapX.FolderCollection folders = client.Folders;
//Create folder
client.CreateFolder("NEW FOLDER", false);
//Message collection 1st option
ImapX.MessageCollection messages = client.Folders["INBOX"].Search("ALL", true); //true - means all message parts will be received from server
//2nd option
foreach (ImapX.Message m in client.Folders["INBOX"].Messages)
{
m.Process();
List attachments = m.Attachments;
string textBody = m.TextBody.TextData;
string htmlBody = m.HtmlBody.TextData;
}
ImapX.Message msg = new ImapX.Message();
msg.Subject = "hello yahoo";
msg.From.Add(new ImapX.MailAddress(fromUserName, fromUserEmail));
msg.To.Add(new ImapX.MailAddress(toUserName, toUserEmail));
msg.HtmlBody.ContentType = "text/html";
msg.HtmlBody.TextData = "it is test message";
ImapX.Attachment atach = new ImapX.Attachment();
atach.FileName = attachmentPath;
msg.Attachments.Add(atach);
if (client.Folders["INBOX"].AppendMessage(msg))
{
Console.WriteLine("message has been appended to INBOX");
}
Feature list supported by library:
- Folder management
- Message management
- Message saving in IMAP folder (like Drafts on Gmail)
- SSL
- Custom IMAP server implementations (like Google and AOL)
- Full IMAP Search compatible
Features to be implemented during near future:
- Offline message storage/synchronization
In ZIP archive you will find actual dll to use and IMAP Search reference document, sorry no documentation at this moment.
Hopefully it will be usefull.
Feb 24, 2010 update:
We have fixed following issues:
- now we correctly support message flags (“DELETED”, “SEEN”, “ANSWERED”, “DRAFT”, “RECENT”) and custom flags
- correctly handling spaces in passwords (need to be tested more, please contact us if you’ll find an issues there)
There are code sample which allows to set message flags:
ImapX.MessageCollection messages = client.Folders["INBOX"].SubFolder["NEWFOLDER"].Search("ALL");
//get list of current message flags
List allFlags = messages[1].Flags;
//set fllag array of flags are in ImapFlags constants
messages[1].SetFlag(ImapX.ImapFlags.SEEN);
Feb 25, 2010 update:
Today we have released version 1.0.5 of the library
Fixed issues:
- now correctly handling different types of subjects from IMAP
March 4, 2010 update:
Today we have released version 1.0.6 of the library with a great performance improvements (up to 4 time faster)
Fixed issues:
- Now it’s possible to search for messages without auto-filling the body, header and other message properties. Added new bool parameter for Search method which indicates to fill properties or no
Here is code example
//result messages + process()
ImapX.MessageCollection messages = client.Folders["G01"].Search("ALL", true);
//result empty messages
ImapX.MessageCollection messages = client.Folders["G01"].Search("ALL", false);
//fill message header info
messages[1].ProcessHeader();
//fill message flags info
messages[1].ProcessFlags();
//fill message body info
messages[1].ProcessBody();
//fill all message info
messages[1].Process();
March 4, 2010 update:
We have updated library to 1.0.6.1 version. Fixed some minor bugs. Thanx to Dalibor.
March 25, 2010 update:
We have updated library to 1.0.6.3 version. Fixed some more minor bugs.
March 26, 2010 update:
We have updated library to 1.0.6.4 version. Added IsDebug property to ImapX.ImapClient
client.isDebug = true; // with this option , all requests and responses are print to Console window
April 14, 2010 update:
We have updated library to 1.1 version. Fixed bugs with message processing, users faced in previous releases.
Please note: if your are facing any problems with message body or if message has no content-type, you may find all body parts in BodyParts collection:
List<MessageContent> bodyParts = msg.BodyParts; //get body : string body = bodyParts[index].ContentStream;
Some users facing problems with different Subject/Body encodings. Please note – ImapX itself doesn’t decode subject/body automatically. For instance if you have subject encoded to BASE64 using UTF8 charset you have to do following techniques:
//preparing subject to be sent
string codedSubject = "=?UTF-8?B?" + Convert.ToBase64String(Encoding.UTF8.GetBytes(subject)) + "?=";
//decoding subject from received message
string decodedSubject = Encoding.UTF8.GetString(Convert.FromBase64String(CodedSubject.Split('?')[4]));
//decoding body from Base64/UTF8 :
string decodedBody = Encoding.UTF8.GetString(Convert.FromBase64String(msg.HtmlBody.TextData));
Thanks to all of users of ImapX. And thank you for you comments, your responses help us to develop better IMAP library.
April 27, 2010 update:
We have updated body processing, ImapX refused to consume some bodies produced by Outlook 2007. It’s fixed in 1.1.0.1 version
May 12, 2010 update:
Updated:
- Message parsers updated
- Fixed problems with special characters in folder names
- Added body part properties: BoundaryNames and PartHeaders
Example:MessageContent body = message.HtmlBody; body.BoundaryNames // name of boundary of this part body.PartHeaders // Collection headers of this part
July 7, 2010 update:
Updated:
- Message parsers updated
- Fixed problems with marking message as seen during processing
- Fixed attachments processing
If you’ll face problems with a message parsing then please use method GetAsString() of class Message. It will allow you to use custom parsers to parse a message
Download
-
[...] ImapX [...]
-
[...] am using this library IMAPX to get [...]
-
[...] ImapX – free for use .NET library | HelloWebApps (hellowebapps.com) [...]
-
[...] downloaded the ImapX library and I need know it is possible get email list using imapx? if not, what is the best quick [...]



Could you provide a strong named version of the DLL? I can’t use it in my project without it being strong named. I tried to disassemble and then sign and reassemble but the project won’t compile with it.
Thanks,
David
Hi,
.
Thks for your library, It works very well
Is there any issue to change the timeout of the different connection methods ?
Hi,
I want to read emails from gmail and I want to get all attachment from message and I want to save this attachments to my server.Is that possible with this library?and is there sample code for this.
thanks
how to get all name of folder in gmail?
Nice.
Hi thanks for this library, so i am trying read the email with special characters as the word “Administración” and return this “Administraci=C3=B3n”,
I don’t understand how use the encoding
I use the spanish lenguage
Please help me
Thanks!
Where is your rss? I cant find it
hey how can i mark email as READ or UNREAD ? plz help !
hi, thanks for such an amazing tool..
I have a question.. how can I access yahoo inbox with it?
I keep getting error “Bad or not correct Path” here is my code so far..
ImapX.ImapClient client = new ImapX.ImapClient(“imap.mail.yahoo.com”, 993, true);
bool result = false;
result = client.Connection();
if (result)
textBox1.Text = “Connected\r\n”;
client._client.SendCommand(“ID (\”GUID\” \”1\”)”);
result = client.LogIn(“xxxx@yahoo.co.uk”, “xxxx”);
if (result)
{
textBox1.Text = textBox1.Text + “Logged in\r\n”;
}
ImapX.MessageCollection messages = client.Folders["Inbox"].Search(“ALL”, true);
for (int s = 0; s < messages.Count; s++)
{
textBox1.Text = textBox1.Text + messages[s].TextBody.TextData + "\r\n";
}
still not sure what I'm doing wrong….
I have a same question
Hi,
when i try to getfolders i receive an error about matrix limits
my connection is true, my login is sucessfull if i want simple know how many dirs the mailbox have client.getfolders.count i receive the message
(i use a private imap service not google)
tks for help
naturally i try to use this before getfolders:
Dim cartelle As ImapX.FolderCollection = client.Folders
and i receive the same exception error.
I read in some post about this error and u say download the new version. I think have the last version.
tks for help
BION I’m imperssed! Cool post!
Hi. First of all I want to say thanks for your library.
I have a few questions:
- How can I get all unreaded messages from some folder?
This code returns NullReferenceException
Folder folder = client.Folders["SomeLabel"];
MessageCollection mc = folder.CheckNewMessage(true);
- How can I mark message as “read”? The code below doesnt work.
mes.SetFlag(ImapFlags.SEEN);
- What can I put into “path” param in the Folder.Search method exept “ALL”?
My apologies. mes.SetFlag(ImapFlags.SEEN) works. Please remove this question from my last post
I have the same problem..
I have the same problem..
Any ideas how to fix this???
Hello,
I want to use IMAPX dll For business use.If need licence to use this DLL or it is free to use.