因此,当消息“弹出”并且我使用检查器时,此工作正常。但是,使用ActiveInlineResponse时,.Send()方法不可用。仅供参考,在这方面我还是个新手,但这对于我们正在推广的应用程序确实很重要。我在早期版本的Office中具有相同的外接程序,效果很好。我无法形容这会给我带来多少帮助。我花了多个小时阅读论坛上的帖子,以尝试自己解决此问题,但我失败了。
我尝试过的一些问题/事情:
代码如下:
public void sendSecure_Click(Office.IRibbonControl control)
{
if (control.Id == "sendSecure" || control.Id == "inSendSecure")
{
Outlook.Explorer exp = Globals.SecMailAddIn.Application.ActiveExplorer();
if(exp.ActiveInlineResponse != null)
{
if(exp.ActiveInlineResponse is Outlook.MailItem)
{
Outlook.MailItem response = null;
response = exp.GetType().InvokeMember("ActiveInlineResponse",
System.Reflection.BindingFlags.GetProperty |
System.Reflection.BindingFlags.Instance |
System.Reflection.BindingFlags.Public,
null, exp, null) as Outlook.MailItem;
if (response != null)
{
//Add the property to the header, save them item and captuer the EntryID and close the item.
AddUserProperty(response, "XYZ");
((Outlook._MailItem)response).Save();
var mailId = response.EntryID;
MessageBox.Show(mailId);
//Close the item
Marshal.ReleaseComObject(response);
Marshal.ReleaseComObject(exp);
//Send the Item Using the entryid.
}
}
}
else
{
Outlook.Inspector oInspOriginal = control.Context as Outlook.Inspector;
if (oInspOriginal.CurrentItem is Outlook.MailItem)
{
Outlook.MailItem oMail = oInspOriginal.CurrentItem as Outlook.MailItem;
AddUserProperty(oMail, "XYZ");
((Outlook._MailItem)oMail).Send();
}
}
}
else if (control.Id == "sendFullSecure" || control.Id == "inSendFullSecure")
{
Outlook.Inspector oInspOriginal = control.Context as Outlook.Inspector;
if (oInspOriginal.CurrentItem is Outlook.MailItem)
{
Outlook.MailItem oMail = oInspOriginal.CurrentItem as Outlook.MailItem;
AddUserProperty(oMail, "XYZZ");
((Outlook._MailItem)oMail).Send();
}
}
else
{
Outlook.Inspector oInspOriginal = control.Context as Outlook.Inspector;
if (oInspOriginal.CurrentItem is Outlook.MailItem)
{
Outlook.MailItem oMail = oInspOriginal.CurrentItem as Outlook.MailItem;
AddUserProperty(oMail, "XYZZ");
((Outlook._MailItem)oMail).Send();
}
}
}
void Explorer_InlineResponseClose()
{
}
private void AddUserProperty(Outlook.MailItem mail, string folderEmailId)
{
Outlook.PropertyAccessor mailPropertyAccessor = null;
try
{
if (string.IsNullOrEmpty(folderEmailId))
return;
mailPropertyAccessor = mail.PropertyAccessor;
mail.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/X-WorksiteFolderEmailId", folderEmailId);
mail.Save();
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
编辑1:
else if (control.Id == "sendFullSecure" || control.Id == "inSendFullSecure")
{
Outlook.Explorer exp = Globals.SecMailAddIn.Application.ActiveExplorer();
if (exp.ActiveInlineResponse != null)
{
if (exp.ActiveInlineResponse is Outlook.MailItem)
{
Outlook.MailItem response = null;
response = exp.GetType().InvokeMember("ActiveInlineResponse",
System.Reflection.BindingFlags.GetProperty |
System.Reflection.BindingFlags.Instance |
System.Reflection.BindingFlags.Public,
null, exp, null) as Outlook.MailItem;
if (response != null)
{
try
{
//Add the property to the header.
AddUserProperty(response, "EBSENDSECURE");
//Get the Current Window Object
IOleWindow winh = exp as IOleWindow;
winh.GetWindow(out IntPtr win);
//Get the Handle from the window object.
AutomationElement newElement = AutomationElement.FromHandle(win);
//Find the Standard Send Button Property and invoke it to send the email.
PropertyCondition sendButtonCondition = new PropertyCondition(AutomationElement.NameProperty, "Send");
AutomationElement sendButton = newElement.FindFirst(TreeScope.Descendants, sendButtonCondition);
if (sendButton != null)
{
MessageBox.Show("The send button was found.");
var invokePattern = sendButton.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
invokePattern.Invoke();
}
//Close the item
Marshal.ReleaseComObject(response);
Marshal.ReleaseComObject(exp);
}
catch (Exception)
{
MessageBox.Show("An error has occurred while sending this email. Please close and reopen outlook to verify that it is sent correctly.");
throw;
}
}
}
}
答案 0 :(得分:0)
是的,OOM阻止了一些用于内联响应的方法。最好的办法就是使用可访问性API模拟“发送”按钮的点击。
如果可以选择使用Redemption,则它会公开SafeExplorer。ActiveInlineResponseSend
方法:
SafeExplorer sExplorer = new Redemption.SafeExplorer();
sExplorer.Item = Application.ActiveExplorer;
sExplorer.ActiveInlineResponseSend();