我是新用户,是C#.net的新用户,这是我的第一个查询。我已将Outlook电子邮件保存在我的本地驱动器中的文件夹中。问题是我必须创建一个回复或回复电子邮件与新的身体。下面是我到目前为止编写的代码。我无法使用CreateItemFromTemplate()
public void IterateMessages(string folderPath, string folderName, string emailName, string attachmentPath, string Subject, string mailDate, string To, string SenderName)
{ try
{
string uBank = string.Empty;
string efolderPath = folderPath + "\\Emails\\";
string tempSubject = string.Empty;
string tempMailDate = string.Empty;
string tempTo = string.Empty;
string tempSenderName = string.Empty;
string tempSName = string.Empty;
string eBody = " Hi,<br /><br /> Body here... <br /> <br /><br /><br /><br />";
//Getting the Folder name from the Path given
foreach (string frname in Directory.GetDirectories(efolderPath))
{
string[] vfolder = frname.Split('\\');
uBank = vfolder.Last(); //getting foldername
if (uBank == folderName) //Comparing values for Validation
{
string[] Files = Directory.GetFiles(frname + "\\", "*.msg", SearchOption.TopDirectoryOnly);
for(int i=0; i < Files.Length; i++)
{
Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
var item = app.Session.OpenSharedItem(Files[i]) as Microsoft.Office.Interop.Outlook.MailItem;
item.Display();
item.Reply(); //Cant reply to the open email here. Some ambiguity..
item.Close(Microsoft.Office.Interop.Outlook.OlInspectorClose.olDiscard);
}
}
}
}
catch (System.Exception e)
{
MessageBox.Show("An error occurred: " + e);
}
}
答案 0 :(得分:1)
MailItem.Reply
返回新的(回复)消息。您需要显示该新消息而不是旧消息。此外,绝对没有理由在循环中创建Outlook.Application
的新实例 - 只需在开始循环文件之前执行一次。