美文网首页
如何自动下载邮件附件到指定文件夹

如何自动下载邮件附件到指定文件夹

作者: 九月_1012 | 来源:发表于2020-10-20 11:38 被阅读0次
    1. 首先确认outlook 2016 user权限
    • 右击outlook,选属性,查看owener是当前用户,还是另有admin用户,需要owener账户进行设置。
    • 打开Outlook - Option - Trust Center - Truster Center Settings - Macro Settings - 勾选Enable all macros。 然后继续在Truster Center Settings - Email Security - 勾选Allow script in shared folders 和 All script in public folders
    • 重启Outlook
    1. 使outlook 2016有“run a script”选项
    • 点击键盘“win键+R”,输入“regedit”;
    • 进入“Computer\HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Security
    • 点击空白处,new->DWORD(32-bit) Value,重命名为“EnableUnsafeClientMailRules”,双击该文件,Value data改为“1”
    • 重启Outlook


      image.png
    1. 在outlook邮箱插入VBA脚本
      点击“Alt + F11”,双击界面编辑框,插入如下代码
    Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
    
    Public Sub SaveAttach(MyItem As Outlook.MailItem)
        SaveAttachment MyItem, "C:\Data\MailAttached\"
        'MsgBox "附件已保存"
    End Sub
    
    Private Sub SaveAttachment(ByVal Item As Outlook.MailItem, path, Optional condition = "*")
        Dim olAtt As Outlook.Attachment
        Dim i As Integer
        If Item.Attachments.Count > 0 Then
            For i = 1 To Item.Attachments.Count
                Set olAtt = Item.Attachments(i)
                If olAtt.FileName Like condition Then
                    olAtt.SaveAsFile path & olAtt.FileName
                End If
            Next
        End If
        Set olAtt = Nothing
        Sleep 100
    End Sub
    
    Private Sub UserForm_Click()
    
    End Sub
    
    1. 创建下载的规则
      注意点击“run a script”,选择刚才的脚本


      image.png

    相关文章

      网友评论

          本文标题:如何自动下载邮件附件到指定文件夹

          本文链接:https://www.haomeiwen.com/subject/kvzrmktx.html