简体   繁体   中英

C# how change Sender field in outlook

How can I change form "to", when i create a new mail (or reply) in outlook? mailItem.Sender and SendUsingAccount don't work.

namespace OutlookAddIn7 { public partial class ThisAddIn { Outlook.Inspectors inspectors;

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {

        inspectors = this.Application.Inspectors;
        inspectors.NewInspector +=
        new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(SendUsingAccountExample);

    }
    void SendUsingAccountExample(Microsoft.Office.Interop.Outlook.Inspector Inspector)
    {
        Outlook.MailItem mailItem = Inspector.CurrentItem as Outlook.MailItem;
        Outlook.NameSpace session = mailItem.Session;
        Outlook.Accounts accounts = session.Accounts;
        mailItem.SendUsingAccount = Application.Session.Accounts[1];
            //mailItem.Sender = accounts[1].CurrentUser.AddressEntry;
            //Microsoft.Office.Interop.Outlook.Recipient recipient = Application.Session.CreateRecipient(accounts[1].CurrentUser.AddressEntry.Address);
    }

如果您使用的是 Exchange,请设置SentOnBehalfOfName属性。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM