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() == )
{
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));