vba - 按类型过滤电子邮件附件文件

标签 vba email outlook

我有一个脚本,当在电子邮件中找不到附件时会发送通知。是否可以检查附件的文件类型并在文件类型不是所需文件类型时发送通知。

得到这样的代码。

    Option Explicit
        Public Sub CheckAttachment(Item As Outlook.MailItem)
            Dim olInspector As Outlook.Inspector
            Dim olDocument As Outlook.DocumentItem
            Dim olSelection As Outlook.Selection
            Dim objAtt As Outlook.Attachment
            Dim ft As FileTypes
            Dim olReply As MailItem
            Dim FileExtension As String
            FileExtension = "jpeg, jpg, tiff, pdf"

            '// Check for attachment
            If Item.Attachments.Count > 1 Then
            GoTo CheckFileType1
                End If



        CheckFileType1:
            If Item.Attachments(Item.Attachments, ".tiff") Then
            GoTo CheckFileType2
            End If

        CheckFileType2:
            If Item.Attachments(Item.Attachments, ".jpeg") Then
            GoTo CheckFileType3
            End If

        CheckFileType3:
            If Item.Attachments(Item.Attachments, ".pdf") Then
            GoTo SendMail
            Else
            Exit Sub
            End If

        SendMail:
            Set olReply = Item.Reply '// Reply if no attachment found
            olReply.Body = "No attachment was found. Re-send the email and ensure that the needed file is attached." & vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf & "This is a system generated message. No need to reply. Thank you."
            olReply.Send

            Set olInspector = Nothing
            Set olDocument = Nothing
            Set olSelection = Nothing


        End Sub

最佳答案

Is it possible to check the file type of the attachment and send a notification if the filetype is not the one needed.

是的,是的。

Attachment类提供 FileName 属性,该属性返回表示附件文件名的字符串。

关于vba - 按类型过滤电子邮件附件文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31578874/

相关文章:

vba - 使用 =COLUMN 函数从表中返回列号

html - 使用 html 格式化电子邮件

html - 如何在 Outlook 中插入 HTML 格式的文本?

html - 标题 =""未在 html 电子邮件中显示

vba - 从指定列复制单元格,删除重复项

vba - Excel 加载项和 VBA 引用的范围是什么?

c# - 如何将 MailMesage 保存到 .msg 文件?

html - outlook.com、microsoft exchange 和 hotmail.com 中的空 HTML 邮件

vba - 如何获得一个函数来引用它所在的单元格?

php - 是什么让 PHP 的 mail() 函数如此缓慢?