I have an application that will be installed on a server and it is connected to the internet. Microsoft Outlook will be installed as well. The system will handle requests from 5 different departments and each department has its own email address.
I have seen this code, Microsoft Outlook Send and Email Automation C# so i know how to send an email using Outlook, but the problem I am facing is changing the sender of the email. How do I setup the configuration of Outlook for each department that needs to send from C#? Is there a way to change the user logged in or something?
Outlook has a property where you can get the list of accounts mapped to it. based on your configuration you can pick up the email sender and send the email.
Microsoft.Office.Interop.Outlook.Accounts accounts = oMsg.Session.Accounts;
for (int i = 1; i <= accounts.Count; i++)
{
string accountfound = accounts[i].DisplayName.ToLower();
if (accountname.ToLower() == accountfound)
{
found = true;
oMsg.SendUsingAccount = accounts[i];
Microsoft.Office.Interop.Outlook.Recipient recipient = oMsg.Session.CreateRecipient(accountfound);
}
}
If you're using Outlook to connect to an Exchange server, you can use the Exchange Web Services Managed API (and particularly the EmailMessage class) to connect directly to the Exchange server without having to worry about configuring the Outlook client on the server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With