- jmai读取多个邮件内的信息
- //需要添加的引用
- using jmail;
- using System.Data.SqlClient;
- using System.Net.Sockets;
- using System.IO;
- public DataTable CreateDataSouce()
- {
- DataTable dt = new DataTable();
- DataRow dr = dt.NewRow();
- //jmail message 类
- Message msg = new Message();
- jmail.POP3Class jpop = new jmail.POP3Class();
- //用户账号信息数据库
- Database db = new Database();
- DataTable dtemail = db.ShowEmai();
- try
- {
- dt.Columns.Add(new DataColumn("主题", typeof(string)));
- dt.Columns.Add(new DataColumn("发件人", typeof(string)));
- dt.Columns.Add(new DataColumn("发件时间", typeof(string)));
- dt.Columns.Add(new DataColumn("EmailName", typeof(string)));
- DataColumn idNumber = new DataColumn("编号");
- idNumber.AutoIncrement = true;
- idNumber.AutoIncrementSeed = 1;
- idNumber.AutoIncrementStep = 1;
- dt.Columns.Add(idNumber);
- for (int j = 0; j < dtemail.Rows.Count; j++)
- {
- string UserName = dtemail.Rows[j]["UserName"].ToString().Trim();
- string UserPwd = dtemail.Rows[j]["UserPwd"].ToString().Trim();
- string POP3ip = dtemail.Rows[j]["Pop3"].ToString().Trim();
- int Port =Convert.ToInt32(dtemail.Rows[j]["port"]);
- //连接邮箱
- jpop = new POP3Class();
- jpop.Connect(UserName, UserPwd, POP3ip, Port);
- if (jpop.Count > 0)
- {
- for (int i = 1; i <= jpop.Count; i++)
- {
- msg = jpop.Messages[i];
- dr = dt.NewRow();
- dr[0] = msg.Subject;
- dr[1] = msg.FromName;
- dr[2] = msg.Date.ToString();
- dr[3] = GetDomain(UserName);
- dt.Rows.Add(dr);
- }
- }
- else
- {
- return null;
- }
- jpop.Disconnect();
- }
- return dt;
- }
- catch(Exception ex)
- {
- return null;
- }
- }
- public string GetDomain(string username)
- {
- string domain = "";
- domain=username.Substring(username.IndexOf("@")+1);
- domain=domain.Substring(0,domain.IndexOf("."));
- return domain;
- }
Jmail读取邮件代码
最新推荐文章于 2013-11-22 13:38:34 发布