0

Trying to go two routes with this. The goal is to let someone attach a file and then on _ItemSend event to run a Regexp to detect certain strings in the filename and then to a Cancel=True or Cancel=False. I have the following code, but the basic problem I'm having is converting the mailItem.Attachments to a String to actually run it through the Regexp. I get alot of errors saying it can't be converted to a String...any ideas?

  Public Sub Application_ItemSend(ByVal Item As Object, _
    ByRef Cancel As Boolean) Handles Application.ItemSend
    Dim mailItem As Outlook.MailItem = TryCast(Item, Outlook.MailItem)
    If mailItem IsNot Nothing Then
        Dim attachments = mailItem.Attachments
        For Each attachment As Outlook.Attachment In attachments
            AttachmentQuery(attachment, mailItem, Cancel)
        Next attachment
    End If

    Dim instance As String
    Dim AttachmentMatchResults As MatchCollection
    Dim attachments1 = mailItem.Attachments
    instance = attachments1.ToString
    Dim returnValue As String
    returnValue = instance.ToString
    Dim RegexObj2 As New Regex("^.*(names|playlist|roster).*$", RegexOptions.Multiline)
    AttachmentMatchResults = RegexObj2.Matches(returnValue)
    If RegexObj2.IsMatch(returnValue) Then
        MsgBox("A key file has been found", MsgBoxStyle.OkCancel)
        Cancel = True
    Else
        Cancel = False
    End If
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343

1 Answers1

0

If you are talking about the string representation/name of individual Attachment objects (rather than the Attachments collection object) then you can use (for the i-th attachment):

mail_item.Attachments(i).FileName
Marcin
  • 1,889
  • 2
  • 16
  • 20