一、首先,需要需要登陆的QQ邮箱账号开启IMAP功能,进入邮箱设置即可,开启IMAP功能后会获取一串密码,这是接下来登陆需要的密码,请务必开启;
二、需要LumiSoft.Net.dll;
三、LumiSoft.Net.dll的开发环境是.Net 2.0 使用Microsoft Visual Studio 系列工具时请注意更改项目环境;Ps:.Net 2.0 不支持 linq
1、声明一个
IMAP_Client client = new IMAP_Client();
实例化client对象;
2、登陆邮箱
client.Connect("imap.qq.com", 993, true);
string path = System.Environment.CurrentDirectory + "//user.txt";
if (!File.Exists(path)) {
Console.WriteLine("请在配置文件中修改账号密码。");
return;
}
string emailAccount;
string password;
using (FileStream fs = new FileStream(path, FileMode.Open)) {
StreamReader sr = new StreamReader(fs);
emailAccount = sr.ReadLine();
password = sr.ReadLine();
}
Console.WriteLine(emailAccount + password);
client.Login(emailAccount, password);
client.SelectFolder("INBOX");
博主使用的文件读取账号和密码方便修改,省的改代码;
3、获取邮件参数设置
var seqSet = IMAP_t_SeqSet.Parse("1:*");
seqSet.GetType();
var items = new IMAP_t_Fetch_i[]
{
new IMAP_t_Fetch_i_Envelope(),
new IMAP_t_Fetch_i_Uid(),//邮件编号---删除邮件会用到
new IMAP_t_Fetch_i_Flags(),//邮件标记-----已读:/Seen(还是\Seen,记不太清了,试一下就成) 未读:不知道...
new IMAP_t_Fetch_i_InternalDate(),
new IMAP_t_Fetch_i_Rfc822()//获取邮件内容需要的参数----未知含义