I'm trying to send mail from my c#.net application, I've used this code:
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);
The mail doesn't get sent, but added to the outbox folder. I suspect that the mail isn't sent because outlook isn't started. So I googled and came up with this:
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);
But once again it end up in the outbox folder. I need to start outlook, because I can't specify the FromMail property in every single client application.config. Any ideas?