码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2015-05-06 17:25:49      阅读:639      评论:0      收藏:0      [点我收藏+]

标签:

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

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

标签:

原文地址:http://www.cnblogs.com/sunkaixuan/p/4482167.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!