【发布时间】:2023-03-13 14:12:01
【问题描述】:
当用户单击我的应用程序中的某个按钮或链接时,我需要打开一个带有预填充附件的新电子邮件窗口。
【问题讨论】:
标签: c#-4.0 outlook office-interop outlook-addin outlook-2010
当用户单击我的应用程序中的某个按钮或链接时,我需要打开一个带有预填充附件的新电子邮件窗口。
【问题讨论】:
标签: c#-4.0 outlook office-interop outlook-addin outlook-2010
您可以使用 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();
}
可以找到工作示例here..
【讨论】:
老问题,但我也遇到了这个问题,所以这里有一个复制和粘贴解决方案:
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 组件的引用。
【讨论】: