2012-11-26 47 views
0

我米使用此代碼在Outlook識別電子郵件地址2010

 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) 

在這部分的代碼從separes附件的文件夾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 

此代碼的工作原理,也許我需要通過電子郵件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 

下面的代碼必須將 「儲蓄銀行德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, "[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 

但代碼不工作做什麼,我錯了????

回答

1

有可能SenderEmailAddress字段產生類似於this question中的輸出。

嘗試用objOLmail.Sender.GetExchangeUser().PrimarySmtpAddress代替objOLmail.SenderEmailAddress

相關問題