alejandro carnero
alejandro carnero

Reputation: 1784

Identify the email address in Outlook 2010

I m using this code

        Public Sub ProcessarAnexo(Email As MailItem)

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

This is the folder where i need to save the attachments

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

In this part the code separes the attachment from the mail

        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

This code works, perhaps i need to separe the attachments by the email adreess

i have write this :

          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

Here the code must assign "Caixa de Entrada" or "Inbox" to the Mapifolder Inbox

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

     For Each objOLmail In Inbox.Items

Here if the mail from [email protected] must go to the folder ""C:\Separados\AlamoLogistica\""

    If InStr(objOLmail.SenderEmailAddress, "[email protected]") >= 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

but the code dont work what i m doing wrong????

Upvotes: 0

Views: 1539

Answers (1)

Kevin Pope
Kevin Pope

Reputation: 2982

It's possible the SenderEmailAddress field is producing something similar to the output in this question.

Try replacing objOLmail.SenderEmailAddress in your If statement with objOLmail.Sender.GetExchangeUser().PrimarySmtpAddress

Upvotes: 1

Related Questions