Network Protocol (iii) IMAP

Source: Internet
Author: User
Tags imap

IMAP(Internet Message Access Protocol, Internet Mail reading Protocol)It is an application layer protocol used to access emails on a remote server from a local mail client.

TestCodeDownload

 

IMAP and POP3 are the most common Internet standard protocols for email access. In fact, most modern mail clients and servers support both. The current version of IMAP is "the first version of IMAP version 4" (imap4rev1 ).Rfc3501.

Compared with POP3, IMAP provides some important functions:

1Supports connection and disconnection.

2Allows multiple customers to connect to one mailbox at the same time.

3.MimePartial and partial access.

4Message status information can be retained on the server.

5You can access multiple mailboxes on the server.

6Supports server-side search.

7Supports a well-defined extension mechanism.

 

Unlike most old Internet protocols, IMAP4 native supports the encryption registration mechanism. The plaintext transmission password is also supported in IMAP4. Because the use of the encryption mechanism requires the consistency between the client and the server, the use of the plaintext password is in some cases of different client and server types (such as Microsoft Windows client and non-Windows Server ). SSL can also be used to encrypt the communication between IMAP4 by transmitting the communication over port 993 on SSL or declaring "and" starttls "when the IMAP4 thread is created ".

IMAP4 uses port 143 to work on TCP/IP connections.

The. NET Framework does not encapsulate IMAP operations. Therefore, the third-party component lumisoft. NET is used.

Lumisoft. NET is an open-source component that implements many protocols,Source codeIs a good reference for learning network protocols.


 

 

Test code:

 

Private   Static   Void Fnimapdemo ()
{
Imap_client Client =   New Imap_client ();
Filestream log =   New Filestream ( @" C: \ log.txt " , Filemode. openorcreate, fileaccess. readwrite );
Streamwriter SW =   New Streamwriter (log );

Try
{
// Connect to the mail server by passing in the mail server address and the port number for the IMAP Protocol
Client. Connect ( " Imap.gmail.com " , 993 , True );
Client. login ( " Mymbrooks " , " ****** " );

Imap_client_fetchhandler fetchhandler =   New Imap_client_fetchhandler ();
Fetchhandler. rfc822 + =   New Eventhandler < Imap_client_fetch_rfc822_eargs > ( Delegate ( Object S, imap_client_fetch_rfc822_eargs E)
{
Memorystream storestream =   New Memorystream ();
E. Stream = Storestream;
E. storingcompleted + =   New Eventhandler ( Delegate ( Object S1, eventargs E1)
{
Storestream. Position =   0 ;
Mail_message mime = mail_message.parsefromstream (storestream);
SW. writeline (mime. bodytext);
});

// get emails
imap_sequenceset seqset = New imap_sequenceset ();
seqset. parse ( " 1: * " );

imap_r_u_list [] list = client. getfolders ( null );
foreach (imap_r_u_list L in List)
{< br> client. selectfolder (L. foldername);

Client. Fetch (
True ,
Seqset,
New Imap_fetch_dataitem [] {
New Imap_fetch_dataitem_rfc822 ()
},
Fetchhandler
);
}
}
Catch
{

}
Finally
{
Sw. Flush ();
Sw. Close ();
Log. Close ();
}
}

 

 

I wrote emails in Gmail to the C: \ log.txt file:

 

Hmail Server Configuration

Hmail Server is a free mail server under Windows, support SMTP, POP3, IMAP protocol, official homepage: http://www.hmailserver.com/

I am using the latest test version:Hmailserver 5.3.4-1913

Supported SQL Server , MySQL , Pgsql Database. Pay attention to the following during installation, SQL Server Very simple. MySQL , You need MySQL x86 lib A DLL Copy Past, Pgsql On Windows Server 2008 R2 SP1 The installation fails. Bug .

First addDomain:

 

Since it was just a test, I used 127.0.0.1 and added two test accounts: user1@127.0.0.1, user2@127.0.0.1.

Configure the SMTP, POP3, and IMAP protocols:

 

Other options are available by default, and are highly scalable. You can configure access rules, DNS, anti-virus, logs, and other features. The combined DNS server can be used as a small enterprise mail server.

 

After configuring the server, configure the client as follows:

 

Add user1 and user2 as set:

 

Try to send an email:

 

You can see that you successfully received the email:

 

Summary:

IMAP is the de facto standard for obtaining emails. Most email service providers support encrypted IMAP services. We recommend that you use IMAP (SSL and TLS) to receive emails during work and life. Lumisoft. NET provides a large number of encapsulated components, which are of great research value. If you are interested, you can study them in depth. Finally, I briefly introduced the installation and configuration of the hmail server. in windows, I can quickly build a small enterprise mail server, which brings great news to many small and medium-sized enterprises.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.