当前位置: 代码迷 >> C# >> .NET C# 使用S22.I地图.dll接收邮件 并且指定收取的文件夹的未读邮件,并且更改未读准态
  详细解决方案

.NET C# 使用S22.I地图.dll接收邮件 并且指定收取的文件夹的未读邮件,并且更改未读准态

热度:111   发布时间:2016-05-05 03:54:08.0
.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));

  相关解决方案