0

我正在使用此代码

        Public Sub ProcessarAnexo(Email As MailItem)

        Dim DiretorioAnexos As String
        Dim MailID As String
        Dim Mail As Outlook.MailItem
        Dim objOLmail As Object

这是我需要保存附件的文件夹

        DiretorioAnexos = "C:\Separados\AlamoLogistica\"
        MailID = Email.EntryID
        Set Mail = Application.Session.GetItemFromID(MailID)

在这部分中,代码将附件与邮件分开

        For Each anexo In Mail.Attachments
             If Right(anexo.FileName, 3) = "xml" Then
                 anexo.SaveAsFile DiretorioAnexos & anexo.FileName
             End If

             If Right(anexo.FileName, 3) = "zip" Then
                anexo.SaveAsFile DiretorioAnexos & anexo.FileName
             End If
        Next
        Set Mail = Nothing

此代码有效,也许我需要通过电子邮件地址分隔附件

我写了这个:

          Dim ns As Outlook.NameSpace
          Dim Inbox As Outlook.MAPIFolder
          Dim appOl As New Outlook.Application

          Dim DiretorioAnexos As String
          Dim MailID As String
          Dim Mail As Outlook.MailItem
          Dim objOLmail As Object

此处代码必须将“Caixa de Entrada”或“收件箱”分配给 Mapifolder 收件箱

     Set ns = appOl.GetNamespace("MAPI")
     Set Inbox = ns.GetDefaultFolder(olFolderInbox)

     For Each objOLmail In Inbox.Items

这里如果来自 longfe@ifdcontroladoria.com.br 的邮件必须到文件夹 ""C:\Separados\AlamoLogistica\""

    If InStr(objOLmail.SenderEmailAddress, "longfe@ifdcontroladoria.com.br") >= 0 Then
       DiretorioAnexos = "C:\Separados\AlamoLogistica\"
        MailID = Email.EntryID
        Set Mail = Application.Session.GetItemFromID(MailID)

        For Each anexo In Mail.Attachments
             If Right(anexo.FileName, 3) = "xml" Then
                 anexo.SaveAsFile DiretorioAnexos & anexo.FileName
             End If

             If Right(anexo.FileName, 3) = "zip" Then
                anexo.SaveAsFile DiretorioAnexos & anexo.FileName
             End If
        Next
    End If

 Next
     Set Mail = Nothing

但是代码不起作用我做错了什么???

4

1 回答 1

1

该字段可能会产生与此问题SenderEmailAddress中的输出类似的内容。

尝试objOLmail.SenderEmailAddress在您的 If 语句中替换为objOLmail.Sender.GetExchangeUser().PrimarySmtpAddress

于 2012-11-26T23:20:09.173 回答