日期:2014-05-18  浏览次数:20836 次

请教一下高人,C#中利用JMail接收邮件后,想把邮件删掉,
请教一下高人,C#中利用JMail接收邮件后,想把邮件删掉,

DeleteSingleMessage(MessageID);
Deletes a single message on the mail server.
Mailbox.DeleteSingleMessage 1

我的问题是:参数MessageID怎么得到呢?

------解决方案--------------------



private List<MailModel> LoadMail()
{
jmail.Message Msg = new jmail.Message();
jmail.POP3 jpop = new jmail.POP3();
List<MailModel> list = new List<MailModel>();
//下面参数依次为:接收邮件的邮箱帐户、接收邮件的邮箱密码、邮箱服务地址、邮箱服务端口
jpop.Connect("163@163.com", "163", "pop.163.com", 110); //163邮箱服务地址与端口
DateTime maxTime = DateTime.Parse("2000-01-01"); //设置接收此日期以後的邮件(读取数据库接收最迟的邮件时间)
if (maxTime == null)
{
maxTime = DateTime.Parse("1900-01-01");
}
string subject;//主题
string body;//内容
string uid;//唯一标识
//如果服务器上有邮件
if (jpop.Count > 0)
{
for (int i = jpop.Count; i > 0; i--)
{
Msg = jpop.Messages[i];
string t = Msg.Headers.GetHeader("Date");
if (Msg.Date > maxTime)
{
subject = EntityManager.Decode(Msg.Headers.GetHeader("Subject"));
body = Msg.HTMLBody != null ? Msg.HTMLBody : Msg.Body;
uid = jpop.GetMessageUID(i);
MailModel mail = new MailModel();
mail.MailContent = body; //邮件内容
mail.MailTitle = subject; //邮件主题
mail.MessageUID = uid; //该邮件在本邮件服务器中的唯一标识
mail.ReceiveTime = Msg.Date; //发送时间
mail.SourceMail = Msg.From; //发送人
mail.SourceName = Msg.FromName != null ? Msg.FromName : Msg.From.Substring(0, Msg.From.IndexOf('@'));//发送别名
mail.Status = 1;//状态()
list.Add(mail);
if (isDelete)
{
jpop.DeleteSingleMessage(i);
}
continue;
}
break;
}
//断开连接
jpop.Disconnect();
}
return list;
}