none
Autometic paste of signature depend on Email domain RRS feed

  • Question

  • Hello,

    I have an idea, but when I want to implemant it, I found an impotent question which cased a problem: How to autometically paste a signature to Outlook email depending on email domains of recipients.

    I have developed Outlook Addin for Outlook 2010 on MSVS 2012.

    I thought that this event will be "ItemSent" because the event is  the best for my idea.

    I have some signatures inside Outlook settings and depending on email domain addresses I want to insert it to latter.

    I found solution:

    private void Item_Send(object Item, ref bool Cancel) {

    // convert to Email MailItem mail = Item as MailItem; // if Email is <Null> if (mail == null) return; // all rights if (mail.Application.ActiveInspector().IsWordMail()) { Inspector ins = mail.Application.ActiveInspector(); if (ins.IsWordMail()) { Microsoft.Office.Interop.Word.Document word = ins.WordEditor as Microsoft.Office.Interop.Word.Document; Micosoft.Office.Core.SignatureSet sing = word.Signatures.

    if (sing.Count >= 0)

    {

    // this code never perform

    }

    } } private void ThisAddIn_Startup(object sender, System.EventArgs e) { if (this.Application != null) this.Application.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(Item_Send); }


    Now, I don't know how I can paste signature from Outlook ...

    Please help me, who know something about it ...

    Thanks In Advance.

    ---

    Regards: Eugene.


    Sunday, July 5, 2015 6:09 PM

All replies

  • Hello Eugene,

    The Signatures property of the Document class from the Word object model returns a SignatureSet collection that represents the digital signatures for a document. So, that is no what you need.

    You need to parse the message body and insert the signature content on your own. There is no special method for that.

    Sunday, July 5, 2015 6:24 PM
  • Hello Eugene,

    The Signatures property of the Document class from the Word object model returns a SignatureSet collection that represents the digital signatures for a document. So, that is no what you need.

    Thanks, :)

    So, In this situation I should to paste my signature from file(s) to my Body property of Outlook object, Right ?!

    This this finally situation ?! - No more solutions ?!

    P.S. If my email document signature were inserted, I need to parse my document for delete/paste old/new signature to my email ?!






    Sunday, July 5, 2015 7:19 PM
  • As far as I know the Outlook stores its signatures in a local folder,for example in Windows Vista its in the

    C:\Users\[UserName]\AppData\Roaming\Microsoft\Signatures.

    Windows Xp:

    [Driver]:\Documents and Settings\[UserName]\Application Data\Microsoft\Signatures

    Then you could modify it by using the FileStream Class. You can try like below codes:

    private void Item_Send(object Item, ref bool Cancel)
    {
    
         // convert to Email
         Outlook.MailItem mail = Item as Outlook.MailItem;
         // if Email is <Null>
         if (mail == null) return;
         // all rights
         if (mail.Application.ActiveInspector().IsWordMail())
         {     
       Outlook.Inspector ins = mail.Application.ActiveInspector();
              if (ins.IsWordMail())
              {
                   Microsoft.Office.Interop.Word.Document word = ins.WordEditor as Microsoft.Office.Interop.Word.Document;
                   Office.SignatureSet sing = word.Signatures;
                   if (sing.Count >= 0)
                   {
                       //this code never perform
                       mail.HTMLBody+= ReadSignature();
                    }
               }
            }
    }
    
    private string ReadSignature()
    
    {
    
                string appDataDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Microsoft\\Signatures";
    
                string signature = string.Empty;
    
                DirectoryInfo diInfo = new DirectoryInfo(appDataDir);
    
                if
    
                (diInfo.Exists)
    
                {
    
                    FileInfo[] fiSignature = diInfo.GetFiles("*.htm");
    
                    if (fiSignature.Length > 0)
    
                    {
    
                        StreamReader sr = new StreamReader(fiSignature[0].FullName, Encoding.Default);
    
                        signature = sr.ReadToEnd();
    
                        if (!string.IsNullOrEmpty(signature))
    
                        {
    
                            string fileName = fiSignature[0].Name.Replace(fiSignature[0].Extension, string.Empty);
    
                            signature = signature.Replace(fileName + "_files/", appDataDir + "/" + fileName + "_files/");
    
                        }
    
                    }
    
                }
    
                return signature;
    
    }
    

    Tuesday, July 7, 2015 8:21 AM