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