我正在尝试从我的 c#.net 应用程序发送邮件,我使用了以下代码:
var mailItem = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
mailItem.Subject = "Error Report from user: " + AuthenticationManager.LoggedInUserName;
mailItem.HTMLBody = "Test email\n"+ReadSignature();
mailItem.To = "test@test.com";
mailItem.Display(true);
邮件不会被发送,而是添加到发件箱文件夹中。我怀疑邮件没有发送,因为 Outlook 没有启动。所以我用谷歌搜索并想出了这个:
var oApp = new Outlook.Application();
Microsoft.Office.Interop.Outlook.NameSpace ns = oApp.GetNamespace("MAPI");
var f = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
Thread.Sleep(5000); // a bit of startup grace time.
var mailItem = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
mailItem.Subject = "Error Report from user: " + AuthenticationManager.LoggedInUserName;
mailItem.HTMLBody = "Test email\n"+ReadSignature();
mailItem.To = "test@test.com";
mailItem.Display(true);
但它再次出现在发件箱文件夹中。我需要启动 Outlook,因为我无法在每个客户端 application.config 中指定 FromMail 属性。有任何想法吗?