Consistently retrieve “From” email addresses acros

2019-08-15 02:06发布

问题:

I am working a standalone c# desktop application that sends out documents and then imports them from Outlook when they are sent back. The application picks up the emails from a specified folder processes them and then saves the senders name plus other stuff to a database.

This works well for Outlook 2003 and 2007 which has the SenderEmailAddress property. However Outlook 2000 and XP does not have this property and will not consistently return name@domain.com. I am providing support for these versions.

I have found that a library called Outlook Redemption will solve this but I am developing in .net and really want to avoid writing to customer registries. I also found MAPI33 a .Net wrapper around MAPI but it is unclear from the forums whether it is still being supported.

Would appreciate any pointers as to a .Net alternative to the Redemption dll or an approach to being able to consistently retrieve an email address across Outlook versions.

Many thanks

AbsFabs

Epilogue: I ended up using a solution from this article http://support.microsoft.com/kb/324530. It comprised creating a reply and then extracting the reply to address of the created mailitem. It worked well for emails sent over the internet and is currently going through Exchange Server testing.

Also found this on my travels http://anoriginalidea.wordpress.com/2008/01/11/getting-the-smtp-email-address-of-an-exchange-sender-of-a-mailitem-from-outlook-in-vbnet-vsto/ it appears to be a touch involved. This might comprise my plan B if my existing implementation does not survive testing.

Thanks for your feedback

AbsFabs

I ultimately wound up using Redemption. Excellent tool for the job. My issue was with having to register the dll when my app was installed. Since my app is written in dotnet it does not need to register anything. I was able to work around the dll registration issue using registry-free COM.

Many thanks for your inspiration.

回答1:

I'm using the Outlook Redemption solution in a C# production code. It works beautifully. With it, you can get the SenderID of a mail message (IRDOMail), and from there, you can use the GetAddressEntryFromID() method of the IRDOSession object.



回答2:

While having a similar problem at work, we decided to go the netMAPI route, which has caused some problems.

The main problem with it is that MAPI managed its own memory, as does .NET meaning that occasionally (we have around 300 people using our in house software) it would cause our application to crash, generating the windows 'report error' dialog rather than our own bug tracking dialog. This was caused by the two overwriting each others memory heaps.

As we have to use an exchange server, we did some research, and discovered that if you wrote the MAPI code in a VB6 app, it would have its own memory space, and thus not overwrite the .NET heap.

It is a rather long winded way of doing things, but thus far we have had no problems, and hundreds (if not thousands) of emails are sent by our staff everyday.



回答3:

Good news is that ou are on the right track with tracking down the right interfaces. The bad news is that 2000 and XP are very poorly supported in .NET because they came before .NET and only with 2003 was their a real effort to get the COM working in .NET.

You solution for these version 2000 and XP is going to consist of you tracking down the right COM interfaces and wrapping them your self. I have had to do this many times for these version of Outlook and it is never pretty. So good luck.



回答4:

Redemption can be used without installing it in the registry - you can use RedemptionLoader in C#, VB.Net, Delphi and C++.

//tell the app where the 32 and 64 bit dlls are located
//by default, they are assumed to be in the same folder as the current assembly and be named 
//Redemption.dll and Redemption64.dll.  
//In that case, you do not need to set the two properties below
RedemptionLoader.DllLocation64Bit = @"c:\SourceCode\Redemption\redemption64.dll";
RedemptionLoader.DllLocation32Bit = @"c:\SourceCode\Redemption\redemption.dll";
//Create a Redemption object and use it
RDOSession session =  RedemptionLoader.new_RDOSession();
session.Logon(Missing.Value, Missing.Value,  Missing.Value, Missing.Value, Missing.Value,  Missing.Value);


回答5:

I've never actually used these, but you could try the Outlook Collaboration Data Objects (CDO). They used to be an add-on that you could install with outlook, but now they are being provided separately.