2016-11-15 16 views
0

私は、メール添付ファイルをサーバーに配置し、代わりに電子メールにURLを入れることで、Outlookアドインを処理しています。送信前にOutlookのメールの本文テキストを更新する方法

1つの問題は、電子メール本文の末尾にURLを追加すると、ユーザーのカーソルが電子メールの先頭にリセットされることです。

関連する問題は、カーソルがテキスト内のどこにあるのかわからないため、URLを正しい場所に挿入できないということです。

ここでは私がやっていることを示すいくつかのコードを示します。簡単にするために、コードは本体がプレーンテキストであると仮定しています。


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

     Application.ItemLoad += new Outlook.ApplicationEvents_11_ItemLoadEventHandler(Application_ItemLoad); 
    } 

    void Application_ItemLoad(object Item) 
    { 

     currentMailItem = Item as Outlook.MailItem; 

     ((Outlook.ItemEvents_10_Event)currentMailItem).BeforeAttachmentAdd += new Outlook.ItemEvents_10_BeforeAttachmentAddEventHandler(ItemEvents_BeforeAttachmentAdd); 


    } 
void ItemEvents_BeforeAttachmentAdd(Outlook.Attachment attachment, ref bool Cancel) 
    { 
     string url = "A URL"; 
     if (currentMailItem.BodyFormat == Outlook.OlBodyFormat.olFormatHTML) 
     { 
      // code removed for clarity 
     } 
     else if (currentMailItem.BodyFormat == Outlook.OlBodyFormat.olFormatRichText) 
     { 
      // code removed for clarity 
     } 
     else 
      currentMailItem.Body += attachment.DisplayName + "<" + url + ">"; 

     Cancel = true; 
    } 
+0

http://stackoverflow.com/questions/38433898/c-sharp-outlook-how-can-i-get-the-cursor-position-被験者フィールド内で – stuartd

答えて

0

使用Application.ActiveInspector.WordEditor Word文書オブジェクトを取得します。 Word Object Modelを使用してすべての変更を実行します。

+0

ありがとう、私はちょうどその領域を見ていた。 –

0

これは私がやりたいようだ:

using Microsoft.Office.Interop.Word; 
    void ItemEvents_BeforeAttachmentAdd(Outlook.Attachment attachment, ref bool Cancel) 
    { 
     if (attachment.Type == Outlook.OlAttachmentType.olByValue) 
     { 
      string url = "A URL"; 
      Document doc = currentMailItem.GetInspector.WordEditor; 
      Selection objSel = doc.Windows[1].Selection; 
      object missObj = Type.Missing; 

      doc.Hyperlinks.Add(objSel.Range, url, missObj, missObj, attachment.DisplayName, missObj); 

      Cancel = true; 
     } 
    } 
関連する問題