Scalabium Software

SMExport advertising
Knowledge for your independence'.
Home Delphi and C++Builder tips


#142: How can I read a sender address for MailItem (MS Outlook)?

Sometime ago I posted a few tips for MS Outlook automation. I want to continue this serie.

If you tried to work with messages from Delphi, you know that received message have the SenderName property (name of sender) but doesn't allow to read the real address of sender. Something like SenderAddress is not available.

Exists a few methods to retrieve this information:

1. help file says that sender is in Recipients collection with Type property - 0 (olOriginator).
But this way is not work for any version of MS Outlook. So just iterate thru collection of Recipients and find an item with Type=0 couldn't return required value

2. as alternative you can read a ReplyTo property - there you'll receive an address (but generally ReplyTo and Sender could be different).
For example, in messages which I send from own mail account these values are different.

3. to create a new MailItem (just will be destroyed without saving in end of work), define a Recipient as value which you received from SenderName of your original message and call a Resolve method - after that you'll recieve a correct email address of this sender.

4. more correct and fast solution is the next:

begin
  objCDO := CreateOLEObject('MAPI.Session');
  objCDO.Logon('', '', False, False);
  objMsg := objCDO.GetMessage(itemOL.EntryID, itemOL.Parent.StoreID);

   s := objMsg.Sender.Address;
   showmessage(s);
   objMsg := UnAssigned;
   objCDO := UnAssigned;
end

where itemOL is a MailItem which contain a SenderName but doesn't contain a SenderAddress:-)


Published: July 29, 2002

See also
 
ABA Picture Convert
dBase Viewer
Viewer for TNEF-files (winmail.dat)
MAPIMail
SMExport suite
SMDBGrid
Paradox to Text converter
ExcelFile Viewer
Metafile Convert
Excel Web-stream
 
 


Contact to webmaster

 

Borland Software Code Gear Scalabium Delphi tips

Copyright© 1998-2024, Scalabium Software. All rights reserved.
webmaster@scalabium.com

SMExport advertising