当用户点击我的应用程序中的某个按钮或链接时,我需要打开一个带有预填充附件的新电子邮件窗口。
答案 0 :(得分:20)
老问题,但我也参与其中,所以这里是一个复制和粘贴解决方案:
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
组件的引用。
答案 1 :(得分: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();
}
可以找到工作示例here ..