确定Outlook 2010中的电子邮件地址

时间:2012-11-26 18:02:42

标签: vba outlook outlook-vba

我正在使用此代码

        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

此代码有效,或许我需要通过电子邮件adreess分隔附件

我写了这个:

          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

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

1 个答案:

答案 0 :(得分:1)

SenderEmailAddress字段可能产生与this question中的输出类似的内容。

尝试使用objOLmail.SenderEmailAddress

替换If语句中的objOLmail.Sender.GetExchangeUser().PrimarySmtpAddress