|
Tim Kempster
Guest
|
Hi
I'm looking for a solution to get the email addresses (the from addresses) for all the accounts within outlook.
I have seen some code on these forums using MAPI but it seems that this will restrict me to a 32 bit application is that right? I need my addin to work on 32 and 64 bit. I'm ok for Outlook 2007 onwards though.
I'd have thought that there was a fairly simple way of achieving this. Even if I can get the send from email address at the the point of
private void adxOutlookAppEvents_ItemSend(object sender, ADXOlItemSendEventArgs e)
that would probably be enough.
It seems like a lot of functionality depends on MAPI but this requires code like
[DllImport("MAPI32.DLL", CharSet=CharSet.Ansi, EntryPoint="HrGetOneProp@12")]
private static extern void HrGetOneProp32(IntPtr pmp, uint ulPropTag, out IntPtr ppProp);
which presumably won't work in 64 bit versions of Outlook. |
|
Posted 04 Nov, 2019 09:02:50
|
|
Top
|
|
Andrei Smolin
Add-in Express team
Posts: 18826
Joined: 2006-05-11
|
Hello Tim,
Get Outlook.Account via MailItem.SendUsingAccount. See Account.SmtpAddress. This works in Outlook 2007+.
Andrei Smolin
Add-in Express Team Leader |
|
Posted 05 Nov, 2019 03:26:12
|
|
Top
|
|
Tim Kempster
Guest
|
|
Posted 06 Nov, 2019 06:05:00
|
|
Top
|
|
Andrei Smolin
Add-in Express team
Posts: 18826
Joined: 2006-05-11
|
Hello Tim,
Tim Kempster writes:
I'm probably missing a reference or something?
Exactly. You need to use interops for Office 2007 or above. In your add-in project, delete existing references to Office interops. In the File Explorer, copy required interops from {Add-in Express}\Redistributables\Interop Assembies\{version} to {your add-in project}\Interops replacing the existing files. Then, in your add-in project, re-add references to copied interop files. If your old interops were version-neutral interops and you use C#, you may need to adjust your source code replacing {some Office collection object type e.g. UserProperties}.Item({some index}) with {some Office collection object type e.g. UserProperties}[{some index}].
Andrei Smolin
Add-in Express Team Leader |
|
Posted 06 Nov, 2019 06:11:04
|
|
Top
|
|
Tim Kempster
Guest
|
Great that seems to have worked. So to understand this correctly if I used the Interop assemblies for 2007 my addin will work with all versions of word over 2007. However if I need to access functionality for say 2016 I have to build with these particular interops ?
Regards |
|
Posted 06 Nov, 2019 06:28:31
|
|
Top
|
|
Andrei Smolin
Add-in Express team
Posts: 18826
Joined: 2006-05-11
|
Hello Tim,
Tim Kempster writes:
So to understand this correctly if I used the Interop assemblies for 2007 my addin will work with all versions of word over 2007.
The exact meaning of "will work" requires me to answer No. An add-in can use any interop version with any version of the corresponding host application. The point is. If the inerop for version 2007 is used, your source code can be used with version 2007 with no modification, directly using early binding. If your add-in is loaded by any other Office version, you have two issue types to be resolved:
1) the interop version (2007) is older than the host application version (2016). In this case, the Office application object model has classes and members missing in the type library. To access such members and classes, you use late binding.
2) the interop version (2016) is newer than the host application version (2007). In this case, the type library has classes and members missing in the office application's object model. The only way to bypass such an issue would be to use a numerous IF statements in the source code.
This asymmetry also causes different cost of source code changes: it is simpler to use late binding.
Now, to prevent your add-in from getting loaded by Office 2000 through 2003, you must set the minOfficeVersionSupported attribute in adxloader.dll.manifest to "12".
Andrei Smolin
Add-in Express Team Leader |
|
Posted 06 Nov, 2019 07:14:35
|
|
Top
|
|
Tim Kempster
Guest
|
Thanks for your details response. I need to do some more reading up on this. I feel this is more complex than I had hoped. I just want to get at the Account information so I can get the send email addresses using code like....
List<string> smtpAccounts = new List<string>();
foreach (Outlook.Account account in OutlookApp.Session.Accounts)
{
string s = account.SmtpAddress;
smtpAccounts.Add(account.SmtpAddress);
}
I built it with 2007 interops and ran on 2016 and it seems to work. You seem to suggest this might not always work so I'll need to read up to understand your answer properly. |
|
Posted 06 Nov, 2019 08:24:03
|
|
Top
|
|
Andrei Smolin
Add-in Express team
Posts: 18826
Joined: 2006-05-11
|
|
Posted 06 Nov, 2019 08:36:10
|
|
Top
|
|