【问题标题】:Outlook Add In VSTOOutlook 添加 VSTO
【发布时间】:2021-12-28 10:59:23
【问题描述】:

我还在编程领域。但现在我遇到了一个小问题。我目前正在开发一个 Outlook 加载项,该加载项接收一封电子邮件并将其作为附件打包到新邮件中,并自动将其发送到特定地址。到目前为止效果很好。但是,只有在我在新窗口中打开了要作为附件发送的邮件时,它才有效。

然而,我的目标是,如果邮件在阅读区打开就足够了。然而,不幸的是,我还没有找到解决这个问题的方法。也许有人可以给我一个链接或一个示例来解决邮件,该邮件当前显示在 Visual Studio 的预览中。作为一种语言,我使用 C#。

到目前为止,我打开的邮件如下:

String path = "C:\\Test\\Mail.msg";

Inspector inspector = Globals.ThisAddIn.Application.ActiveInspector();
MailItem mailitem = inspector.CurrentItem as MailItem

但是我如何到达可以在阅读区预览的邮件呢?

非常感谢您的帮助。

【问题讨论】:

    标签: c# email outlook vsto preview


    【解决方案1】:

    要从 Outlook 的资源管理器窗口中获取当前选定的项目,您需要使用以下代码:

            if (Application.ActiveExplorer().Selection.Count > 0)
            {
                Object selObject = this.Application.ActiveExplorer().Selection[1];
                if (selObject is Outlook.MailItem)
                {
                    Outlook.MailItem mailItem =
                        (selObject as Outlook.MailItem);
                    itemMessage = "The item is an e-mail message." +
                        " The subject is " + mailItem.Subject + ".";
                    mailItem.Display(false);
                }
                else if (selObject is Outlook.ContactItem)
                {
                    Outlook.ContactItem contactItem =
                        (selObject as Outlook.ContactItem);
                    itemMessage = "The item is a contact." +
                        " The full name is " + contactItem.Subject + ".";
                    contactItem.Display(false);
                }
                else if (selObject is Outlook.AppointmentItem)
                {
                    Outlook.AppointmentItem apptItem =
                        (selObject as Outlook.AppointmentItem);
                    itemMessage = "The item is an appointment." +
                        " The subject is " + apptItem.Subject + ".";
                }
                else if (selObject is Outlook.TaskItem)
                {
                    Outlook.TaskItem taskItem =
                        (selObject as Outlook.TaskItem);
                    itemMessage = "The item is a task. The body is "
                        + taskItem.Body + ".";
                }
                else if (selObject is Outlook.MeetingItem)
                {
                    Outlook.MeetingItem meetingItem =
                        (selObject as Outlook.MeetingItem);
                    itemMessage = "The item is a meeting item. " +
                         "The subject is " + meetingItem.Subject + ".";
                }
            }
    

    但如果您需要在 Explorer 视图中获取所有选定的项目,则需要遍历 Selection 对象中的所有项目。

    【讨论】:

    • 哇,非常感谢。不行 ;-) 非常感谢您的帮助,
    【解决方案2】:

    使用Application.ActiveExplorer.Selection 集合循环选择的消息并适当地处理它们。

    请记住(就像Application.ActiveInspector) 一样,您可以拥有MailItem 以外的项目,例如ContactItemAppointmentItemReportItem 等。您需要处理这样的项目。

    【讨论】:

    • 太好了,非常感谢。我马上试试。
    • 如果回复回答了您的问题,请注明。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2015-05-20
    • 2016-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-04
    • 2019-12-17
    • 2017-03-31
    相关资源
    最近更新 更多