如何避免在 Outlook 中一次撰写两封邮件
How to avoid two compose mail at a time in Outlook
我正在尝试通过 C# 代码插件自定义 Outlook。它可以正常工作,但是当打开两个或多个撰写邮件(通过新邮件)时,会出现一些问题。所以我想避免在 Outlook 中同时打开两个或多个撰写邮件。我的 Outlook 版本是 2013.
在下面的代码中,我尝试在发送点击事件时发送一个 link 的附件。如果此人同时打开两个或多个撰写邮件,这将崩溃(我在我的项目中为此编写了很多代码以获得 link 的附加代码和其他代码)。如何避免两次撰写邮件或为两次撰写邮件对话保持不同的会话?
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.Application oApp = new Outlook.Application();
无需在 ItemSend 事件处理程序中创建新的 Outlook 应用程序实例。相反,您需要使用加载项 class.
的应用程序 属性
Display 方法接受一个允许显示模态的布尔参数 window。在那种情况下,用户应该在打开另一个检查器 windows 之前关闭这样的 windows。只需将 true 传递给该方法即可。
而且单个Outlook实例可以同时存在,所以只能有一个session。
我正在尝试通过 C# 代码插件自定义 Outlook。它可以正常工作,但是当打开两个或多个撰写邮件(通过新邮件)时,会出现一些问题。所以我想避免在 Outlook 中同时打开两个或多个撰写邮件。我的 Outlook 版本是 2013.
在下面的代码中,我尝试在发送点击事件时发送一个 link 的附件。如果此人同时打开两个或多个撰写邮件,这将崩溃(我在我的项目中为此编写了很多代码以获得 link 的附加代码和其他代码)。如何避免两次撰写邮件或为两次撰写邮件对话保持不同的会话?
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.Application oApp = new Outlook.Application();
无需在 ItemSend 事件处理程序中创建新的 Outlook 应用程序实例。相反,您需要使用加载项 class.
的应用程序 属性Display 方法接受一个允许显示模态的布尔参数 window。在那种情况下,用户应该在打开另一个检查器 windows 之前关闭这样的 windows。只需将 true 传递给该方法即可。
而且单个Outlook实例可以同时存在,所以只能有一个session。