I've got an outlook script which shows you the recipient and prompts the user "Are you sure you wish to send this e-mail to XXX?" However, we have an issue with a plugin we use to send secure files which prompts the user twice from the script instead of once. They tell me to loop through the items.Attachments property to check for a filename ending with ".sf". If it contains this then to abort my script. Can anyone tell me how to do this?

Private Sub Application_ItemSend _ (ByVal Item As Object, Cancel As Boolean)
Dim strMsg As String
Dim Atmt As Variant

If Item.Class = "43" Then
   For Each Atmt In Item.Attachments
       If Right(Atmt.FileName, 3) = ".sf" Then
          GoTo NonEmailError
       End If
   Next Atmt

   If Item.CC = "" Then
      strMsg = "To recipients: " & Item.To & vbCrLf & _
       "Are you sure you want to send this message?"
   Else
      strMsg = "To recipients: " & Item.To & vbCrLf & _
      "Cc recipients: " & Item.CC & vbCrLf & _
      "Bcc recipients: " & Item.BCC & vbCrLf & _
       "Are you sure you want to send this message?"
   End If
Else
    GoTo NonEmailError
End If

On Error GoTo NonEmailError

NonEmailError:
' The item being sent was not an e-mail and so don't prompt the user anything
Exit Sub

End Sub
link|improve this question
On compiling I get an error: Can't find project or library and it highlights "Right". – Untalented Sep 13 '11 at 13:37
I added VBA.Right instead of just "Right" and it compiles now. However, it just skips everything it seems and doesn't even prompt the user about sending the message. – Untalented Sep 13 '11 at 13:53
feedback

1 Answer

You want a For Each loop in your script that loops through the attachment list. Something like the below. Note, this is pseudo-code. I haven't tried it:

For Each Atmt In item.Attachments
    If Right(Atmt.FileName, 3) = ".sf" Then
       --  Your code here
    EndIf
Next Atmt
link|improve this answer
Thanks for the tip. Here is the actual code, which I'm getting a compile error which says "Can't find project or library" and highlights the "Right" command you had above. Let me know if the code below looks correct and how to remedy if possible. I ran out of room so only posted a portion and can't get the formatting right it seems. – Untalented Sep 9 '11 at 18:16
Private Sub Application_ItemSend _ (ByVal Item As Object, Cancel As Boolean) Dim strMsg As String Dim Atmt As Variant For Each Atmt In Item.Attachments If Right(Atmt.FileName, 3) = ".sf" Then GoTo NonEmailError End If Next Atmt 'strMsg = Item.Class If Item.Class = "43" Then If Item.CC = "" Then strMsg = "To recipients: " & Item.To & vbCrLf & _ "Are you sure you want to send this message?" Else Other stuff – Untalented Sep 9 '11 at 18:17
Paste the code into your question. You can format it there – Rhys Gibson Sep 11 '11 at 20:44
Code added, hope you can help. – Untalented Sep 13 '11 at 13:27
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.