OL98: How to Programmatically Sign or Encrypt Mail Messages (279012)



The information in this article applies to:

  • Microsoft Outlook 98

This article was previously published under Q279012

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.

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 creating solutions with Microsoft Outlook, click the article numbers below to view the articles in the Microsoft Knowledge Base:

180826 OL98: Resources for Custom Forms and Programming

182349 OL98: Questions About Custom Forms and Outlook Solutions


Modification Type:MinorLast Reviewed:3/9/2005
Keywords:kbhowto kbSCRAPKeep KB279012