C# 4.0 如何打开Outlook';s带有预填充附件的新邮件窗口
当用户单击我的应用程序中的某个按钮或链接时,我需要打开一个带有预填充附件的新电子邮件窗口。您可以使用outlook的互操作服务来完成此操作C# 4.0 如何打开Outlook';s带有预填充附件的新邮件窗口,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 = "
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();
}
可以找到工作示例..旧问题,但我也遇到了这个问题,所以这里有一个复制粘贴解决方案:
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组件的引用。因此它看起来像是在后台使用Outlook发送邮件。问题是如何实际打开新的邮件窗口,并附上一个附件,让我可以选择在发送之前添加电子邮件。最后,有人和我有同样的担心。我从GridView创建了临时excel。我只想打开一封附有excel的新outlook邮件,让用户按Send。我认为此答案应标记为解决方案。