2017-05-09 3 views
0

私は2つの電子メールアカウントを持つOutlookアドインを作成しようとしていますが、私はデフォルトのメールセットに返信メールを設定したいと考えています。現在、送信電子メールのデフォルトは、送信されたアカウントのいずれかになります。私はオンラインでチェックして、同じような投稿を見ましたが、電子メールメッセージを閉じると、コードは私がもう選択したデフォルトのメールを設定しません。あなたは助けてもらえますか?以下は私のコードです:常にデフォルトの電子メールセットを使用してメールを送信します。 Outlookは、電子メールメッセージがキャンセルされるまで動作します。

using System; 

using System.Collections.Generic; 

using System.Linq; 

using System.Text; 

using System.Xml.Linq; 

using Outlook = Microsoft.Office.Interop.Outlook; 

using Office = Microsoft.Office.Core; 

using System.DirectoryServices.AccountManagement; 

using System.Windows.Forms; 

using System.Runtime.InteropServices; 

    namespace OutlookAddIn1{ 
     public partial class ThisAddIn 
     { 
      private Outlook.Inspectors inspectors; 
      private Outlook.Accounts accounts; 
      private Outlook.MailItem mailItem; 
      private void ThisAddIn_Startup(object sender, System.EventArgs e) 
      { 
       inspectors = this.Application.Inspectors; 
       inspectors.NewInspector += new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector); 
      } 


    void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector) 
      { 
      mailItem =Inspector.CurrentItem; 

       accounts = Application.Session.Accounts; 
      if (mailItem != null) 
       { 
         if (mailItem.EntryID == null) 
         { 
          foreach (Outlook.Account account in accounts) 
       { 
           String strname = "xxxx"; 

           if (account.SmtpAddress.ToString().IndexOf(strname)>0) 
           { 
            mailItem.SendUsingAccount =account; 

           } 
          } 
          } 
      } 

     } 
     } 
    } 

    #region VSTO generated code 

     /// <summary> 
     /// Required method for Designer support - do not modify 
     /// the contents of this method with the code editor. 
     /// </summary> 
     private void InternalStartup() 
     { 


      this.Startup += new System.EventHandler(ThisAddIn_Startup); 
      this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown); 


     } 

     #endregion 
} 

ありがとう!

答えて

0

まず、最初のActivateイベントがOutlookアイテムにアクセスするのを待つことをお勧めします。

とにかく変更をプログラムで保存するには、Saveメソッドを使用してアイテムを保存する必要があります。これは、Microsoft Outlookアイテムを現在のフォルダに保存するか、または新しいアイテムであればアイテムタイプのOutlookのデフォルトフォルダ。

+0

こんにちはユージーン、お返事ありがとうございます。あなたはそれのためのコードを共有することができますか? – Derrick

+0

こんにちはユージーン、それは働いた!私の参照はhttps://www.pcreview.co.uk/threads/inspector-activate-event-under-vs2005-c.3206710/から来ました。たくさんありがとう!!! – Derrick

関連する問題