Microsoft KB Archive/279013

From BetaArchive Wiki
Knowledge Base


OL2000: How to Programmatically Sign or Encrypt Mail Messages

Article ID: 279013

Article Last Modified on 3/9/2005



APPLIES TO

  • Microsoft Outlook 2000 Standard Edition



This article was previously published under Q279013


SUMMARY

The Outlook object model does not provide direct support for programmatically signing or encrypting mail messages. However, you can create a solution that automatically signs or encrypts mail messages.

MORE INFORMATION

Outlook was not designed to provide full functionality for digitally signing and encrypting e-mail messages. However, you can use the CommandBars object model, which is exposed through the Outlook object model, to create a client-based solution that may suit your needs.

For example, you can create a custom mail message form that only allows users to send the message if it is digitally signed or encrypted. You can add Microsoft Visual Basic Scripting Edition (VBScript) code to the form to programmatically "push" the commands to sign or encrypt the mail message. In this scenario, the custom form is typically set as the default form for the entire organization by using the Forms Administrator utility. For additional information about the Forms Administrator utility and where to obtain it, click the article number below to view the article in the Microsoft Knowledge Base:

241235 OL2000: Utility Available to Change Default Outlook Forms


The following VBScript code sample uses the CommandBar ID value of 719, which corresponds to the button to add a digital signature. If you want to programmatically encrypt the mail message instead, use the CommandBar ID value of 718.

Option Explicit

Function Item_Send()

   Dim oDigSign
   Dim oCBs

   Set oDigSignCtl = Item.GetInspector.CommandBars.FindControl(, 719)

   If oDigSignCtl Is Nothing Then
      ' Add the toolbar button to the item.
      Set oCBs = Item.GetInspector.CommandBars
      Set oDigSignCtl = oCBs.Item("Standard").Controls.Add(, 719,,,True)
   End If

   ' Check to make sure the button is not dimmed.
   If oDigSignCtl.Enabled = True Then
      ' Check to make sure the button is not depressed.
      If oDigSignCtl.State = 0 Then oDigSignCtl.Execute
   Else
      MsgBox "You do not have a digital signature! " & _
             "This mail will not be sent."
      ' Cancel the send to only allow sending of signed mail.
      Item_Send = False
      Exit Function
   End If

   Set oCBs = Nothing
   Set oDigSignCtl = Nothing

End Function
                

NOTE: The Collaboration Data Objects (CDO) 1.21 object model does not expose any functionality that allows you to programmatically sign or encrypt e-mail messages.

REFERENCES

For additional information about available resources and answersto commonly asked questions about Microsoft Outlook solutions, click the article number below to view the article in the Microsoft Knowledge Base:

146636 OL2000: Questions About Custom Forms and Outlook Solutions



Additional query words: OutSol OutSol2000 vbscript OL20

Keywords: kbhowto KB279013