troubleshooting Question

Interop Outlook Sending Mail from another mailbox

Avatar of elmbrook
elmbrook asked on
18 Comments1 Solution3728 ViewsLast Modified:

I have a number of mailboxes setup in Outlook.

I would like to use Interop to send an email but not from the default outlook account.

Lets say I have the following email boxes
1. Main email mailbox (default)
2. support mailbox
3. info mailbox
4. accounts mailbox

How do I go about sending an email using the accounts mailbox.

The below code send the email from the mail email box.  

// Create the Outlook application.
                Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();

                // Get the NameSpace and Logon information.
                Microsoft.Office.Interop.Outlook.NameSpace oNS = oApp.GetNamespace("mapi");

                // Log on by using a dialog box to choose the profile.
                oNS.Logon(Missing.Value, Missing.Value, true, true);

                // Create a new mail item.
                Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

                // Set the subject.
                oMsg.Subject = _subject;

                // Set HTMLBody.
                oMsg.HTMLBody = _message;

                oMsg.To = _recipient;
                oMsg.CC = _cc;
                oMsg.BCC = _bcc;

                // Add a recipient.
                //Microsoft.Office.Interop.Outlook.Recipients oRecips = (Microsoft.Office.Interop.Outlook.Recipients)oMsg.Recipients;

                // TODO: Change the recipient in the next line if necessary.
                //Microsoft.Office.Interop.Outlook.Recipient oRecip = (Microsoft.Office.Interop.Outlook.Recipient)oRecips.Add(_recipient);

                // Send.
                (oMsg as Microsoft.Office.Interop.Outlook._MailItem).Send();

                // Log off.

                // Clean up.
                //oRecip = null;
                //oRecips = null;
                oMsg = null;
                oNS = null;
                oApp = null;

Technology Manager

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 18 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 18 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros