.NET C# 使用S22.Imap.dll接收郵件 並且指定收取的文件夾的未讀郵件,並且更改未讀准態


   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.WriteLine(string.Format("==============>沒有新郵件!"));
                        return;
                    }
                    Console.WriteLine(string.Format("==============>開始檢測"));
                    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);

 注:默認 MSG 是獲取的TEXT 郵件內容要獲取HTML內容代碼如下

 
        
  

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));


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM