【发布时间】:2020-04-11 09:02:18
【问题描述】:
我正在使用 Outlook 使用 c# 撰写电子邮件
我使用的代码如下:
object outlookApp = null;
object mailitem = null;
object att = null;
Type typeOutlook = Type.GetTypeFromProgID("Outlook.Application");
Type typeMailItem = null;
Type typeAttachment = null;
outlookApp = Activator.CreateInstance(typeOutlook);
object[] parameters = new object[1] { 0 };
mailitem = typeOutlook.InvokeMember("CreateItem", System.Reflection.BindingFlags.InvokeMethod, null, outlookApp, parameters);
typeMailItem = mailitem.GetType();
att = typeMailItem.InvokeMember("Attachments", System.Reflection.BindingFlags.GetProperty, null, mailitem, null);
typeAttachment = att.GetType();
parameters = new object[1] { sSubject };
typeMailItem.InvokeMember("Subject", System.Reflection.BindingFlags.SetProperty, null, mailitem, parameters);
parameters = new object[1] { "someone@stackoverflow.com" };
typeMailItem.InvokeMember("To", System.Reflection.BindingFlags.SetProperty, null, mailitem, parameters);
parameters = new object[4] { @"c:\somefile.txt", 1, 1, "somefile.txt" };
try
{
typeAttachment.InvokeMember("Add", System.Reflection.BindingFlags.InvokeMethod, null, att, parameters);
}
catch (Exception exAtt) { }
object inspector = typeMailItem.InvokeMember("GetInspector", System.Reflection.BindingFlags.InvokeMethod, null, mailitem, null);
Type typInspector = inspector.GetType();
//typInspector.InvokeMember("Activate", System.Reflection.BindingFlags.InvokeMethod, null, inspector, null);
parameters = new object[1] { true };
typInspector.InvokeMember("Display", System.Reflection.BindingFlags.InvokeMethod, null, inspector, parameters);
//parameters = new object[1] { true };
//typeMailItem.InvokeMember("Display", System.Reflection.BindingFlags.InvokeMethod, null, mailitem, parameters);
问题是,在某些机器上,对话框没有显示在我的应用程序前面。关于为什么的任何想法?我似乎无法理解。如上所述,我尝试使用邮件项目中的显示和检查员中的显示,但这并不能解决问题。 非常感谢任何帮助!
【问题讨论】:
-
你指的是什么对话框?
-
试试 mailItem.Display(true);
-
我指的是撰写电子邮件对话框。我已经尝试过 Display(true) - 它在示例中,在注释行中,但无论如何谢谢!
-
好吧,我去年实现了一个类似的模块。在我的答案中发布下面的代码 sn-p 应该可以帮助您
-
您好 MSantos,您能否确认下面的代码 sn-p 或任何其他答案是否帮助您解决了您的问题,如果是,请考虑点击绿色复选框接受它
标签: c# outlook late-binding