We help IT Professionals succeed at work.

Outlook 2007 - Append emails ?

Medium Priority
291 Views
Last Modified: 2012-05-12
I would like a macro that does the below
when the user clicks "SEND" on an email message

1. displays "Is this email confidential"
2. adds "This is a confidential email, do not ...." below the signature line

Does anyone have an example ?
Comment
Watch Question

Commented:
I recommend you use a program like the Exlaimer product.

Author

Commented:
I would like a script if possible.

Does anyone have one ?
Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
Okay, here's the basic idea.  Add the following code to the MailSend method of the Application.  It will prompt you with a question before sending, and add the text if Yes.  I think it may change the format of the message though depending on if you are doing plain text, versus HTML etc.  Not sure how to get around that.

Add this code to the ThisOutlookSession area of the VBA IDE.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
  Answer = MsgBox("Is this email confidential?", vbYesNoCancel, "Confidential")
  Select Case Answer
    Case vbYes
      Item.Body = Item.Body & vbCrLf & "This is a confidential email, do not ...."
    Case vbCancel
      Cancel = True
  End Select
End Sub

Open in new window

~bp

Author

Commented:
Works, but double spaces my signature line even after removing vbCrLf
Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
What message format are you using?

~bp

Author

Commented:
HTML (attached)
s003.jpg
Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
This gets us a bit closer I think, but I will try and explore further over the weekend.  Wanted to share this much though in case you wanted to probe.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
  Answer = MsgBox("Is this email confidential?", vbYesNoCancel, "Confidential")
  Select Case Answer
    Case vbYes
      If Item.BodyFormat = olFormatHTML Then
        Item.HTMLBody = Replace(Item.HTMLBody, "</body></html>", "This is a confidential email, do not ....</body></html>")
      Else
        Item.Body = Item.Body & vbCrLf & "This is a confidential email, do not ...."
    End If
    Case vbCancel
      Cancel = True
  End Select
End Sub

Open in new window

~bp
Test your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016
Commented:
You can also add some HTML formatting to the added text, here's a sample of that.  Hope this helps, let me know how you make out.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
  Answer = MsgBox("Is this email confidential?", vbYesNoCancel, "Confidential")
  Select Case Answer
    Case vbYes
      If Item.BodyFormat = olFormatHTML Then
        Item.HTMLBody = Replace(Item.HTMLBody, "</body></html>", "<br><font size=1 color=red face=""Arial"">This is a confidential email, do not ....</font></body></html>")
      Else
        Item.Body = Item.Body & vbCrLf & "This is a confidential email, do not ...."
    End If
    Case vbCancel
      Cancel = True
  End Select
End Sub

Open in new window

~bp

Author

Commented:
Looks good and seems to work in my testing.

How can I run "Application_ItemSend2"
(which checks for the word "attached")
after the below runs ?
-------------------------------------------------------
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
  Answer = MsgBox("Is this email confidential?", vbYesNoCancel, "Confidential")
  Select Case Answer
    Case vbYes
      If Item.BodyFormat = olFormatHTML Then
        Item.HTMLBody = Replace(Item.HTMLBody, "</body></html>", "This is a confidential email, do not ....</body></html>")
      Else
        Item.Body = Item.Body & vbCrLf & "This is a confidential email, do not ...."
    End If
    Case vbCancel
      Cancel = True
  End Select
End Sub
Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
If Application_ItemSend2 is a Sub, then just do the following on a line:

Application_ItemSend2

or, if it takes parms:

Application_ItemSend2 parm1, parm2, ...

~bp

Explore More ContentExplore courses, solutions, and other research materials related to this topic.