title: Sending email from the specified Outlook Account
body: <p>I am using Outlook2013 which has a number of mailboxes from both exchange and pop servers.(Rob@mydomain.com[default exchange], rob@somethingdifferent.com[POP], support@mydomain.com[exchange])</p>
  
  <p>I am trying to use Outlook automation to send an email using the support@mydomain.com account. </p>
  
  <p>The problem I am having is the below code creates a mail item in the support outbox but the from field is rob@mydomain.com not support@mydomain.com. This stops it from being sent. </p>
  
  <p>I would like to change the from address to support@mydomain.com. I thought that by setting the Sendusingaccount property did this. </p>
  
  <p>Any help is greatly appreciated.</p>
  
  <pre><code>    public static string Send_Email_Outlook(string _recipient, string _message, string _subject, string _cc, string _bcc, string accountname)
      {
          try
          {
  
              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;
  
  
              #region Send via another account
  
              if (accountname.Trim().Length != 0)
              {
                  Microsoft.Office.Interop.Outlook.Accounts accounts = oMsg.Session.Accounts;
                  for (int i = 1; i &lt;= accounts.Count; i++)
                  {
                      string accountfound = accounts[i].DisplayName.ToLower();
                      if (accountname.ToLower() == accountfound)
                      {
                          oMsg.SendUsingAccount = accounts[i]; // Send using support account
                          Microsoft.Office.Interop.Outlook.Recipient recipient = oMsg.Session.CreateRecipient(accountfound);
                          oMsg.Sender = recipient.AddressEntry;
                          break;
                      }
                  }
              }
              #endregion
  
              // Send.
              (oMsg as Microsoft.Office.Interop.Outlook._MailItem).Send();
  
              // Log off.
              oNS.Logoff();
  
              // Clean up.
              //oRecip = null;
              //oRecips = null;
              oMsg = null;
              oNS = null;
              oApp = null;
  
  
          }
  
       // Return Error Message
          catch (Exception e)
          {
              return e.Message;
          }
  
          // Default return value.
          return "";
  
      }
  </code></pre>