CopyPastor

Detecting plagiarism made easy.

Score: 1.8771357920058196; Reported for: String similarity, Exact paragraph match Open both answers

Original Post

Original - Posted on 2015-09-04
by Dmitry Streblechenko



            
Present in both answers; Present only in the new answer; Present only in the old answer;

Outlook adds the signature to the new unmodified messages (you should not modify the body prior to that) when you call `MailItem.Display` (which causes the message to be displayed on the screen) - Outlook will populate the message body with the signature.
Note as of July 2017, `MailItem.GetInspector` in Outlook 2016 no longer inserts the signature. Only `MailItem.Display` does.
Once the signature is added, read the `HTMLBody` property and merge it with the HTML string that you are trying to set. Note that you cannot simply concatenate 2 HTML strings - the strings need to be merged. E.g. if you want to insert your string at the top of the HTML body, look for the `"<body"` substring, then find the next occurrence of ">" (this takes care of the `<body>` element with attributes), then insert your HTML string after that ">".
Outlook Object Model does not expose signatures at all.
On a general note, the name of the signature is stored in the account profile data accessible through the [IOlkAccountManager][1] Extended MAPI interface. Since that interface is Extended MAPI, it can only be accessed using C++ or Delphi. You can see the interface and its data in [OutlookSpy][2] if you click the `IOlkAccountManager` button.<br> Once you have the signature name, you can read the HTML file from the file system (keep in mind that the folder name (Signatures in English) is localized). <br> Also keep in mind that if the signature contains images, they must also be added to the message as attachments and the `<img>` tags in the signature/message body adjusted to point the `src` attribute to the attachments rather than a subfolder of the Signatures folder where the images are stored.<br> It will also be your responsibility to merge the HTML styles from the signature HTML file with the styles of the message itself.
If using [Redemption][3] is an option, you can use its [RDOAccount][4] object (accessible in any language, including VBA). New message signature name is stored in the `0x0016001F` property, reply signature is in `0x0017001F`. You can also use the [RDOAccount][4].`ReplySignature` and `NewSignature` properties.<br> Redemption also exposes [RDOSignature][5].`ApplyTo` method that takes a pointer to the [RDOMail][6] object and inserts the signature at the specified location correctly merging the images and the styles:
set Session = CreateObject("Redemption.RDOSession") Session.MAPIOBJECT = Application.Session.MAPIOBJECT set Drafts = Session.GetDefaultFolder(olFolderDrafts) set Msg = Drafts.Items.Add Msg.To = "user@domain.demo" Msg.Subject = "testing signatures" Msg.HTMLBody = "<html><body>some <b>bold</b> message text</body></html>" set Account = Session.Accounts.GetOrder(2).Item(1) 'first mail account if Not (Account Is Nothing) Then set Signature = Account.NewMessageSignature if Not (Signature Is Nothing) Then Signature.ApplyTo Msg, false 'apply at the bottom End If End If Msg.Send




[1]: https://msdn.microsoft.com/en-us/library/office/ff960327.aspx [2]: http://www.dimastr.com/outspy [3]: http://www.dimastr.com/redemption [4]: http://www.dimastr.com/redemption/RDOAccount.htm [5]: http://www.dimastr.com/redemption/rdosignature.htm [6]: http://www.dimastr.com/redemption/RDOMail.htm
Outlook adds the signature to the new unmodified messages (you should not modify the body prior to that) when you call `MailItem.Display` (which causes the message to be displayed on the screen) or when you access the `MailItem.GetInspector` property - you do not have to do anything with the returned Inspector object, but Outlook will populate the message body with the signature.
Once the signature is added, read the `HTMLBody` property and merge it with the HTML string that you are trying to set. Note that you cannot simply concatenate 2 HTML strings - the strings need to be merged. E.g. if you want to insert your string at the top of the HTML body, look for the `"<body"` substring, then find the next occurrence of ">" (this takes care of the `<body>` element with attributes), then insert your HTML string after that ">".
Outlook Object Model does not expose signatures at all.
On a general note, the name of the signature is stored in the account profile data accessible through the [IOlkAccountManager][1] Extended MAPI interface. Since that interface is Extended MAPI, it can only be accessed using C++ or Delphi. You can see the interface and its data in [OutlookSpy][2] if you click the `IOlkAccountManager` button.<br> Once you have the signature name, you can read the HTML file from the file system (keep in mind that the folder name (Signatures in English) is localized. <br> Also keep in mind that if the signature contains images, they must also be added to the message as attachments and the `<img>` tags in the signature/message body adjusted to point the `src` attribute to the attachments rather than a subfolder of the Signatures folder where the images are stored.<br> It will also be your responsibility to merge the HTML styles from the signature HTML file with the styles of the message itself.
If using [Redemption][3] is an option, you can use its [RDOAccount][4] object (accessible in any language, including VBA). New message signature name is stored in the `0x0016001F` property, reply signature is in `0x0017001F`. You can also use the [RDOAccount][4].`ReplySignature` and `NewSignature` properties.<br> Redemption also exposes [RDOSignature][5].`ApplyTo` method that takes a pointer to the [RDOMail][6] object and inserts the signature at the specified location correctly merging the images and the styles:
set Session = CreateObject("Redemption.RDOSession") Session.MAPIOBJECT = Application.Session.MAPIOBJECT set Drafts = Session.GetDefaultFolder(olFolderDrafts) set Msg = Drafts.Items.Add Msg.To = "user@domain.demo" Msg.Subject = "testing signatures" Msg.HTMLBody = "<html><body>some <b>bold</b> message text</body></html>" set Account = Session.Accounts.GetOrder(2).Item(1) 'first mail account if Not (Account Is Nothing) Then set Signature = Account.NewMessageSignature if Not (Signature Is Nothing) Then Signature.ApplyTo Msg, false 'apply at the bottom End If End If Msg.Send

**EDIT**: as of July 2017, `MailItem.GetInspector` in Outlook 2016 no longer inserts the signature. Only `MailItem.Display` does.

[1]: https://msdn.microsoft.com/en-us/library/office/ff960327.aspx [2]: http://www.dimastr.com/outspy [3]: http://www.dimastr.com/redemption [4]: http://www.dimastr.com/redemption/RDOAccount.htm [5]: http://www.dimastr.com/redemption/rdosignature.htm [6]: http://www.dimastr.com/redemption/RDOMail.htm

        
Present in both answers; Present only in the new answer; Present only in the old answer;