I programmed a wpf application that sends an outlook mail through the default logged in user.
This is my code:
using System;
using System.Configuration;
using System.IO;
using System.Net;
using System.Net.Mail;
using System.Runtime.InteropServices;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
namespace FileOrganizer
{
class Program
{
private void CreateMailItem()
{
Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem mailItem = app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
mailItem.Subject = "This is the subject";
mailItem.To = "someone@example.com";
mailItem.Body = "This is the message.";
mailItem.Attachment.Add(logPath);//logPath is a string holding path to the log.txt file
mailItem.Importance = Microsoft.Office.Tools.Outlook.OlImportance.olImportanceHigh;
mailItem.Display(false);
}
}
}
I saw this post:
How to send a mail using Microsoft.Office.Interop.Outlook.MailItem by specifying the From Address
But i can't find the Outlook.Accounts option in my project. It just doesn't appear.
Does anyone have a solution for this problem?
My main goal of course is to send my mail using different user.