title: Collecting emails from Outlook Inbox with Delphi
body: <p>I wrote some code to read emails from Outlook Inbox and collect attachments.</p>
  <p>This is working just fine. I am using Outlook 2019/Office 365.</p>
  <p>I can use both <code>Mail.SenderEmailAddress</code> or <code>Mail.Sender.Address</code> to get the email address of the sender.</p>
  <p>When deploying my application to another computer with Outlook 2016, I get this error:</p>
  <blockquote>
  <p>EOleError: Method 'Sender' not supported by automation object</p>
  </blockquote>
  <p>Same for <code>Mail.SenderEmailAddress</code></p>
  <p>Outlook 2016 or 2019 have the same code stream. See <a href="https://www.msoutlook.info/question/200" rel="nofollow noreferrer">Outlook versions, build numbers and other trivia</a>.</p>
  <p>Could you help understanding why I get such error on my client's computer and how can I fix that problem?</p>
  <p>Are you aware of a free/commercial library or components that could do that smoothly?</p>
  <p>This is somehow linked with my other question about <a href="https://stackoverflow.com/questions/64213396/sending-outlook-email-with-delphi">Sending Outlook Email with Delphi</a>.</p>
  <pre><code>try
    Outlook:=GetActiveOleObject('Outlook.Application') ;
  except
    Outlook:=CreateOleObject('Outlook.Application') ;
  end;
  
  try
    oNameSpace := Outlook.GetNamespace('MAPI');
    oNameSpace.Logon;
  
    Inbox:= oNameSpace.GetDefaultFolder(6);
    iNbMail:= Inbox.Items.Count;
  
    for i:= iNbMail downto 1 do
    begin
      if VarIsNull(Inbox.Items[i]) or VarIsEmpty(Inbox.Items[i])  then
        Continue;
  
      Mail:= Inbox.Items[i];
      EmailAddress:= Mail.Sender.Address;
      // EmailAddress:= Mail.SenderEmailAddress;
            
      UnReadFlag:= Mail.UnRead;
      iNbAttach := Mail.Attachments.Count;
  
      for j := iNbAttach downto 1 do
      begin
        Attachment:= Mail.Attachments[j];
        if ExtractFileExt(Attachment.FileName) = '.pdf' then
        begin
          SaveName:= TPath.Combine(InboxFolder, Attachment.FileName);
          Attachment.SaveAsFile(SaveName);
        end;
      end;
      Mail.UnRead:= False;
    end;
  finally
    Outlook:= Unassigned;
    oNameSpace:= Unassigned;
    Inbox:= Unassigned;
    Mail:= Unassigned;
  end;
  </code></pre>