【问题标题】:How to avoid two compose mail at a time in Outlook如何避免在 Outlook 中一次撰写两封邮件
【发布时间】:2015-04-24 17:53:40
【问题描述】:

我正在尝试通过 C# 代码插件自定义 Outlook。它可以工作,但是当打开两个或多个撰写邮件(通过新邮件)时,会出现一些问题。所以我想避免在 Outlook 中同时打开两个或多个撰写邮件。我的 Outlook 版本是 2013。

在下面的代码中,我尝试在发送点击事件时发送附件的链接。如果此人同时打开两个或多个撰写邮件,这将崩溃(我在我的项目中为此编写了很多代码来获取附加代码的链接以及其他人)。如何避免两个撰写邮件或为两个撰写邮件对话维护不同的会话?

void Application_ItemSend(object Item, ref bool Cancel)
{
    int attachcountbs=0;
    StringBuilder sendinglink = new StringBuilder();
    string[] comingstrbuilder = Convert.ToString(SPForm.urlofattach).Split('\n');
    Outlook.Application oApp = new Outlook.Application();
    Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);           
    StringBuilder sb = new StringBuilder();

    //sb.AppendLine("-------------Internal Use-------------<br/>");
    //sb.AppendLine("<a href='" + Class1.test + "'>" + Class1.test + "</a>");

    if (Item is Outlook.MailItem)
    {
        Outlook.MailItem mail = (Outlook.MailItem)Item;
        Outlook.NameSpace session = mail.Session;
        attachcountbs = mail.Attachments.Count;

        int arraycount = comingstrbuilder.Count();
        int checkattach=1;
        for (int i = 0; i < arraycount; i++)
        {
            if (attachcountbs < checkattach)
            {
                break;
            }
            if (comingstrbuilder[i].Contains(mail.Attachments[checkattach].DisplayName))
            {

            //}
            //if (comingstrbuilder[i] == mail.Attachments[checkattach].DisplayName)
            //{
                sendinglink.AppendLine(comingstrbuilder[i]);
                checkattach++;
            }
        }

        if (mail.Attachments.Count == 0)
        {
            mail.HTMLBody = "";
        }
        else
        {
            mail.HTMLBody += "-------------Internal Use-------------<br/>";

            //mail.HTMLBody += "<a href='" + Class1.test + "'>" + Class1.test + "</a>";
            //mail.HTMLBody += SPForm.urlofattach.ToString();
            mail.HTMLBody += sendinglink.ToString();
            SPForm.urlofattach.Clear();
        }
    }
}

【问题讨论】:

  • 试图阻止用户以他们想要的方式使用 Outlook 似乎是 ... 错误 ... 解决方案。我建议更多地关注让你的代码优雅地处理这种情况。
  • 比你......我的代码有一些其他逻辑来处理更多新邮件窗口............

标签: c# outlook-addin


【解决方案1】:

我注意到以下代码:

 Outlook.Application oApp = new Outlook.Application();

无需在 ItemSend 事件处理程序中创建新的 Outlook 应用程序实例。相反,您需要使用加载项类的 Application 属性。

Display 方法接受一个允许显示模式窗口的布尔参数。在这种情况下,用户应该在打开另一个检查器窗口之前关闭这些窗口。只需将 true 传递给方法即可。

单个 Outlook 实例也可以同时存在,因此只能有一个会话。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-16
    • 2021-06-16
    • 1970-01-01
    • 1970-01-01
    • 2013-09-15
    • 1970-01-01
    • 2016-04-25
    • 1970-01-01
    相关资源
    最近更新 更多