【问题标题】:How to open Outlook's new mail window with prepopulated attachment如何使用预填充的附件打开 Outlook 新邮件窗口
【发布时间】:2023-03-13 14:12:01
【问题描述】:

当用户单击我的应用程序中的某个按钮或链接时,我需要打开一个带有预填充附件的新电子邮件窗口。

【问题讨论】:

标签: c#-4.0 outlook office-interop outlook-addin outlook-2010


【解决方案1】:

您可以使用 Outlook 的互操作服务来做到这一点

using Outlook = Microsoft.Office.Interop.Outlook;

 Outlook.MailItem mail = Application.CreateItem(
        Outlook.OlItemType.olMailItem) as Outlook.MailItem;
    mail.Subject = "Quarterly Sales Report FY06 Q4";
    Outlook.AddressEntry currentUser =
        Application.Session.CurrentUser.AddressEntry;
    if (currentUser.Type == "EX")
    {
        Outlook.ExchangeUser manager =
            currentUser.GetExchangeUser().GetExchangeUserManager();
        // Add recipient using display name, alias, or smtp address
        mail.Recipients.Add(manager.PrimarySmtpAddress);
        mail.Recipients.ResolveAll();
        mail.Attachments.Add(@"c:\sales reports\fy06q4.xlsx",
            Outlook.OlAttachmentType.olByValue, Type.Missing,
            Type.Missing);
        mail.Send();
    }

可以找到工作示例here..

【讨论】:

  • 所以看起来它使用 Outlook 实际在后台发送邮件。问题是询问如何实际打开带有附件的新消息窗口,让我可以选择在发送之前添加到电子邮件中。
  • 终于有人和我有同样的担心了。我从 GridView 创建了临时 excel。我只想打开一个附有 excel 的新 Outlook 消息,然后让用户按发送。
【解决方案2】:

老问题,但我也遇到了这个问题,所以这里有一个复制和粘贴解决方案:

Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

oMsg.Subject = "subject something";
oMsg.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML;
oMsg.HTMLBody = "text body"; //Here comes your body;
oMsg.Attachments.Add("c:/temp/test.txt", Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
oMsg.Display(false); //In order to display it in modal inspector change the argument to true

您需要在项目中添加对Microsoft.Office.Interop.Outlook 组件的引用。

【讨论】:

  • 我认为这个答案应该被标记为解决方案。
猜你喜欢
  • 1970-01-01
  • 2011-05-31
  • 2011-02-07
  • 2016-05-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多