. Net c # Use S22.Imap. dll to receive mails and specify the unread mails in the folder to be received, and change the unread quasi-State,

Source: Internet
Author: User
Tags imap

. Net c # Use S22.Imap. dll to receive mails and specify the unread mails in the folder to be received, and change the unread quasi-State,

String host = Conf. configInfo. POP_Host; int port = Conf. configInfo. POP_Port; string username = Conf. configInfo. mailName; string password = Conf. configInfo. mailPassword; using (S22.Imap. imapClient client = new S22.Imap. imapClient (host, port, username, password) {var unseen = client. search (SearchCondition. unseen (), Conf. configInfo. selectFolder); if (unseen = null | unseen. count () = 0) {Console. W RiteLine (string. Format ("================> no new email! "); Return;} Console. writeLine (string. format ("================> start detection"); foreach (uint uid in unseen) {var msg = client. getMessage (uid, true, Conf. configInfo. selectFolder); try {Fetchcallback (msg, uid); client. setMessageFlags (uid, Conf. configInfo. selectFolder, MessageFlag. seen) ;}catch (Exception ex) {throw ex ;}}}

 

 

var msg= client.GetMessage(uid,true,Conf.ConfigInfo.SelectFolder);

Note: by default, MSG is the obtained TEXT mail content. The code for obtaining HTML content is as follows:

 
  

Var dataStream = msg. AlternateViews [0]. ContentStream;
Byte [] byteBuffer = new byte [dataStream. Length];
String altbody = msg. BodyEncoding. GetString (byteBuffer, 0, dataStream. Read (byteBuffer, 0, byteBuffer. Length ));

Related Article

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.