110,535
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using LumiSoft.Net.Mime;
using LumiSoft.Net.POP3.Client;
namespace WebApplication6
{
public class pop
{
public List<Mime> GetEmails()
{
//需要首先设置这些信息
string pop3Server = "pop.qq.com"; //邮箱服务器 如:"pop.sina.com.cn";或 "pop.tom.com" 好像sina的比较快
int pop3Port = 110; //端口号码 用"110"好使。最好看一下你的邮箱服务器用的是什么端口号
bool pop3UseSsl = false;
string username = "*********"; //你的邮箱用户名
string password = "*********"; //你的邮箱密码
List<string> gotEmailIds = new List<string>();
List<Mime> result = new List<Mime>();
using (POP3_Client pop3 = new POP3_Client())
{
try
{
//与Pop3服务器建立连接
pop3.Connect(pop3Server, pop3Port, pop3UseSsl);
//验证身份
pop3.Authenticate(username, password, false);
//获取邮件信息列表
POP3_ClientMessageCollection infos = pop3.Messages;
foreach (POP3_ClientMessage info in infos)
{
//每封Email会有一个在Pop3服务器范围内唯一的Id,检查这个Id是否存在就可以知道以前有没有接收过这封邮件
if (gotEmailIds.Contains(info.UID))
continue;
//获取这封邮件的内容
byte[] bytes = info.MessageToByte();
//记录这封邮件的Id
gotEmailIds.Add(info.UID);
//解析从Pop3服务器发送过来的邮件信息
Mime mime = Mime.Parse(bytes);
result.Add(mime);
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
return result;
}
}
}
求各路大神来瞄一眼