【发布时间】: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