我创建了以下类来打开光盘上现有的 Outlook .msg 文件(“模板”),更改一些属性,添加附件并将其保存回光盘的另一个位置。但是,当我打开 Outlook 时,除了保存位置之外,我的收件箱中还会出现一个新文件!我根本不想保存到任何 Outlook 文件夹,只需修改磁盘上的文件。如何防止它保存到我的收件箱?
public class OutlookMailManager
{
public const string OutlookExtn = ".msg";
public void GenerateMail(string toAddress, string fromAddress, string templateFile, string outputFile, string attachmentFile)
{
MailItem item = OpenMessage(templateFile);
item.To = toAddress;
item.SentOnBehalfOfName = fromAddress;
item.Attachments.Add(attachmentFile);
SaveMessage(outputFile, item);
}
private MailItem OpenMessage(string fileName)
{
var app = new Application();
return (MailItem)app.Session.OpenSharedItem(fileName);
}
private void SaveMessage(string fileName, MailItem item)
{
fileName = Path.ChangeExtension(fileName, OutlookExtn);
item.SaveAs(fileName, OlSaveAsType.olMSG);
}
}