采用DataGrid现实
//读取收件箱内信息
private void button1_Click(object sender, EventArgs e)
{
DataTable mydt = new DataTable();
mydt.TableName = "InBox";
mydt.Columns.Add(new DataColumn("SenderName", typeof(string)));
mydt.Columns.Add(new DataColumn("SenderAddress", typeof(string)));
mydt.Columns.Add(new DataColumn("Subject", typeof(string)));
mydt.Columns.Add(new DataColumn("SendTime", typeof(string)));
mydt.Columns.Add(new DataColumn("ReceiveTime", typeof(string)));
mydt.Columns.Add(new DataColumn("SendTime1", typeof(DateTime)));
mydt.Columns.Add(new DataColumn("ReceiveTime1", typeof(DateTime)));
if (NetMAPI.MAPIInit())
{
NetMAPI mapi = new NetMAPI();
if (mapi.Login())
{
if (mapi.OpenMessageStore())
{
if (mapi.OpenInbox())
{
if (mapi.GetContents())
{
int count = mapi.GetRowCounts();
SmsMessage msg;
StringBuilder s = new StringBuilder(140);
int i = 0;
DataRow dr;
while (mapi.GetNextMessage(out msg, false))
{
i++;
dr = mydt.NewRow();
msg.GetSenderName(s);
dr["SenderName"] = s.ToString();
//MessageBox.Show(s.ToString());
msg.GetSenderEmail(s);
dr["SenderAddress"] = s.ToString();
//MessageBox.Show(aa);
//MessageBox.Show(s.ToString());
msg.GetSubject(s);
dr["Subject"] = s.ToString();
////MessageBox.Show(s.ToString());
msg.GetSubmitTime(s);
dr["SendTime"] = s.ToString();
msg.GetReceivedTime(s);
dr["ReceiveTime"] = s.ToString();
msg.Dispose();
mydt.Rows.Add(dr);
if (i == count - 1)
{
break;
}
}
}
}
}
mapi.Logout();
}
}
else
{
MessageBox.Show("faile");
}
NetMAPI.Term();
this.dataGrid1.DataSource = mydt;
}
//读取发件箱内短信
private void button2_Click(object sender, EventArgs e)
{
DataTable mydt = new DataTable();
mydt.TableName = "SendedBox";
mydt.Columns.Add(new DataColumn("SenderName", typeof(string)));
mydt.Columns.Add(new DataColumn("SenderAddress", typeof(string)));
mydt.Columns.Add(new DataColumn("Subject", typeof(string)));
mydt.Columns.Add(new DataColumn("SendTime", typeof(string)));
mydt.Columns.Add(new DataColumn("ReceiveTime", typeof(string)));
mydt.Columns.Add(new DataColumn("SendTime1", typeof(DateTime)));
mydt.Columns.Add(new DataColumn("ReceiveTime1", typeof(DateTime)));
if (NetMAPI.MAPIInit())
{
NetMAPI mapi = new NetMAPI();
if (mapi.Login())
{
if (mapi.OpenMessageStore())
{
if (mapi.OpenSentItems())
{
if (mapi.GetContents())
{
SmsMessage msg;
StringBuilder s = new StringBuilder(140);
StringBuilder s1 = new StringBuilder(25);
StringBuilder s2 = new StringBuilder(25);
int i = 0;
DataRow dr;
while (mapi.GetNextMessage(out msg, false))
{
i++;
dr = mydt.NewRow();
msg.GetRecipients();
SmsMessage.RecipientType tt;
msg.GetNextRecipient(s1, s2, out tt);
dr["SenderName"] = s1.ToString();
dr["SenderAddress"] = s2.ToString();
//MessageBox.Show(aa);
//MessageBox.Show(s.ToString());
msg.GetSubject(s);
dr["Subject"] = s.ToString();
////MessageBox.Show(s.ToString());
msg.GetSubmitTime(s);
dr["SendTime"] = s.ToString();
msg.GetReceivedTime(s);
dr["ReceiveTime"] = s.ToString();
msg.Dispose();
mydt.Rows.Add(dr);
//if (i > 230)
//{
// break;
//}
}
}
}
}
mapi.Logout();
}
}
else
{
MessageBox.Show("faile");
}
NetMAPI.Term();
this.dataGrid1.DataSource = mydt;
}
这两段代码读取的是收件箱和发件箱里全部短信,还不是很理想.....
WM短信读取(C#)
转载下一篇:C#实现简单断点续传
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
C++实现进程通信(WM_COPYDATA,MFC,C#)
1、简介当应用程序将数据传递给另一个应用程序时发送此消息。This message is sent when an application passes data to anoth
c++ win32开发 进程通信 网络通信 copydata -
C++ VS C# 短信拦截(转)
http://hi.baidu.com/uncheck/blog/item/e98bbb833d1489ab4c
ide 3c microsoft ico #include