读取邮件收件箱,已发件箱,发件箱等等的总数,容量.以及未读邮件数.
请各位朋友,教教小弟啊.
C#读取邮件
答案:2 悬赏:40 手机版
解决时间 2021-03-04 15:17
- 提问者网友:沉默的哀伤
- 2021-03-03 20:59
最佳答案
- 五星知识达人网友:琴狂剑也妄
- 2021-03-03 22:09
写个读邮件的给你看看,至于读数量,研究下就出来了
protected void ReadEmail_Click(object sender, EventArgs e)
{
try
{
TcpClient tcpclient = new TcpClient(); // create an instance of TcpClient
tcpclient.Connect("pop.gmail.com", 995); // HOST NAME POP SERVER and gmail uses port number 995 for POP
System.Net.Security.SslStream sslstream = new SslStream(tcpclient.GetStream()); // This is Secure Stream // opened the connection between client and POP Server
sslstream.AuthenticateAsClient("pop.gmail.com"); // authenticate as client
//bool flag = sslstream.IsAuthenticated; // check flag
System.IO.StreamWriter sw = new StreamWriter(sslstream); // Asssigned the writer to stream
System.IO.StreamReader reader = new StreamReader(sslstream); // Assigned reader to stream
sw.WriteLine("USER your_gmail_user_name@gmail.com"); // refer POP rfc command, there very few around 6-9 command
sw.Flush(); // sent to server
sw.WriteLine("PASS your_gmail_password");
sw.Flush();
sw.WriteLine("RETR 1"); // this will retrive your first email
sw.Flush();
sw.WriteLine("Quit "); // close the connection
sw.Flush();
string str = string.Empty;
string strTemp = string.Empty;
while ((strTemp = reader.ReadLine()) != null)
{
if (strTemp == ".") // find the . character in line
{
break;
}
if (strTemp.IndexOf("-ERR") != -1)
{
break;
}
str += strTemp;
}
Response.Write(str);
Response.Write("<BR>" + "Congratulation.. ....!!! You read your first gmail email ");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
protected void ReadEmail_Click(object sender, EventArgs e)
{
try
{
TcpClient tcpclient = new TcpClient(); // create an instance of TcpClient
tcpclient.Connect("pop.gmail.com", 995); // HOST NAME POP SERVER and gmail uses port number 995 for POP
System.Net.Security.SslStream sslstream = new SslStream(tcpclient.GetStream()); // This is Secure Stream // opened the connection between client and POP Server
sslstream.AuthenticateAsClient("pop.gmail.com"); // authenticate as client
//bool flag = sslstream.IsAuthenticated; // check flag
System.IO.StreamWriter sw = new StreamWriter(sslstream); // Asssigned the writer to stream
System.IO.StreamReader reader = new StreamReader(sslstream); // Assigned reader to stream
sw.WriteLine("USER your_gmail_user_name@gmail.com"); // refer POP rfc command, there very few around 6-9 command
sw.Flush(); // sent to server
sw.WriteLine("PASS your_gmail_password");
sw.Flush();
sw.WriteLine("RETR 1"); // this will retrive your first email
sw.Flush();
sw.WriteLine("Quit "); // close the connection
sw.Flush();
string str = string.Empty;
string strTemp = string.Empty;
while ((strTemp = reader.ReadLine()) != null)
{
if (strTemp == ".") // find the . character in line
{
break;
}
if (strTemp.IndexOf("-ERR") != -1)
{
break;
}
str += strTemp;
}
Response.Write(str);
Response.Write("<BR>" + "Congratulation.. ....!!! You read your first gmail email ");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
全部回答
- 1楼网友:孤独的牧羊人
- 2021-03-03 23:16
c#实现outlook2003邮件内容读取
outlook.applicationclass olapp = new outlook.applicationclass();
outlook.namespace ns = olapp.getnamespace("mapi");
outlook.mapifolder selectfolder = null;
outlook.mailitem mi = null;
// 获得收件箱信息
selectfolder = ns.getdefaultfolder(outlook.oldefaultfolders.olfolderinbox);
this.label1.text = "收件箱:共有" + selectfolder.items.count.tostring() + "封邮件";
this.label1.refresh();
dt.columns.add("1", typeof(string));
dt.columns.add("2", typeof(string));
dt.columns.add("3", typeof(string));
dt.columns.add("4", typeof(string));
dt.columns.add("5", typeof(string));
datarow dr = null;
string isread = "未读";
int i = 1;
foreach (object item in selectfolder.items)
{
mi = item as outlook.mailitem;
if (mi.unread == false) { isread = "已读"; }
dr = dt.newrow();
dr["1"] = i.tostring();
dr["2"] = mi.subject;
dr["3"] = mi.creationtime.tostring();
dr["4"] = isread;
dr["5"] = mi.body;
dt.rows.add(dr);
i++;
this.label3.text ="正在读取:"+ i.tostring();
this.label3.refresh();
}
this.datagridview1.datasource = dt;
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯