【问题标题】:How modify existing Outlook .msg file without saving to Outlook inbox using Interop如何使用 Interop 修改现有 Outlook .msg 文件而不保存到 Outlook 收件箱
【发布时间】:2022-04-03 03:32:12
【问题描述】:

我创建了以下类来打开光盘上现有的 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);
    }
}

【问题讨论】:

    标签: c# .net email outlook office-interop


    【解决方案1】:

    您可以使用扩展 MAPI(仅限 C++ 或 Delphi)和 OpenIMsgOnIStg 函数或 Redemption(任何语言,我是它的作者) - 创建 RDOSession 对象的实例,调用 RDOSession.GetMessageFromMsgFile(返回RDOMail 对象的实例),修改它,调用RDOMail.SaveRDOMail.SaveAs

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-24
      • 1970-01-01
      • 1970-01-01
      • 2014-12-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多