当用户单击我的应用程序中的某个按钮或链接时,我需要打开一个带有预填充附件的新电子邮件窗口。
问问题
18355 次
2 回答
26
老问题,但我也遇到了这个问题,所以这里有一个复制和粘贴解决方案:
Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
oMsg.Subject = "subject something";
oMsg.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML;
oMsg.HTMLBody = "text body"; //Here comes your body;
oMsg.Attachments.Add("c:/temp/test.txt", Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
oMsg.Display(false); //In order to display it in modal inspector change the argument to true
您需要 Microsoft.Office.Interop.Outlook
在项目中添加对组件的引用。
于 2015-11-04T08:39:12.980 回答
3
您可以使用 Outlook 的互操作服务来完成
using Outlook = Microsoft.Office.Interop.Outlook;
Outlook.MailItem mail = Application.CreateItem(
Outlook.OlItemType.olMailItem) as Outlook.MailItem;
mail.Subject = "Quarterly Sales Report FY06 Q4";
Outlook.AddressEntry currentUser =
Application.Session.CurrentUser.AddressEntry;
if (currentUser.Type == "EX")
{
Outlook.ExchangeUser manager =
currentUser.GetExchangeUser().GetExchangeUserManager();
// Add recipient using display name, alias, or smtp address
mail.Recipients.Add(manager.PrimarySmtpAddress);
mail.Recipients.ResolveAll();
mail.Attachments.Add(@"c:\sales reports\fy06q4.xlsx",
Outlook.OlAttachmentType.olByValue, Type.Missing,
Type.Missing);
mail.Send();
}
工作示例可以在这里找到..
于 2012-09-11T05:13:50.553 回答