110,561
社区成员
发帖
与我相关
我的任务
分享
DataTable dt = new DataTable();
dt.Columns.Add("CreationTime", typeof(string));
dt.Columns.Add("Title", typeof(string));
dt.Columns.Add("Content", typeof(string));
var app = new Microsoft.Office.Interop.Outlook.Application();
var ns = app.GetNamespace("MAPI");
ns.Logon("Outlook", Type.Missing, false, false);
var inbox = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
for (int i = 1; i <= inbox.Items.Count; i++)
{
if (inbox.Items[i].UnRead)
{
if (inbox.Items[i].Subject.Contains(""))
{
DataRow dr = dt.NewRow();
dr["CreationTime"] = inbox.Items[i].CreationTime.ToString();
dr["Title"] = inbox.Items[i].Subject;
dr["Content"] = inbox.Items[i].Body;
dt.Rows.Add(dr);
var mail = inbox.Items[i].Reply();
mail.To = inbox.Items[i].SenderEmailAddress;
mail.Subject = "Hello";
mail.HTMLBody = ExecuteBAT(@"E:\1.bat") + mail.HTMLBody;
mail.Send();
}
}
}
ns.Logoff();
Marshal.ReleaseComObject(inbox);
Marshal.ReleaseComObject(ns);
Marshal.ReleaseComObject(app);
inbox = null;
ns = null;
app = null;