首页 > 学院 > 开发设计 > 正文

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

2019-11-17 02:24:24
字体:
来源:转载
供稿:网友

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


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表