views:

116

answers:

2

Okay, the specs have changed on this one somewhat. Maybe someone can help me with this new problem.

Manually, what the user is doing is opening an new message in Outlook (2007 now) which has the "From..." field exposed. They open this up, select a certain account from the Global Address List, and send the message on behalf of that account.

Is this possible to do?

I can get the AddressEntry from the Global address list like so:

        AddressList list = null;
        foreach (AddressList addressList in _outlookApp.Session.AddressLists)
        {
            if (addressList.Name.ToLower().Equals("global address list"))
            {
                list = addressList;
                break;
            }
        }

        if (list != null)
        {
            AddressEntry entry = null;
            foreach (AddressEntry addressEntry in list.AddressEntries)
            {
                if (addressEntry.Name.ToLower().Equals("outgoing mail account"))
                {
                    entry = addressEntry;
                    break;
                }
            }
         }

But I'm not sure I can make an Account type from the Address Entry. It seems to happen manually, when they select the address to send from. How do I mirror this in the Interop?

Thanks!

(My Original Question):

I developed a small C# program to send email using the Outlook 2007 interop. The client required that the mail not be send using the default account - they had a secondary account they needed used.

No problem - I used the Microsoft.Office.Interop.Outlook.Account class to access the availabled accounts, and choose the correct one.

Now, it turns out they need this to work in Outlook 2003. Of course, the Account class doesn't exist in the Outlook interop 11.0.

How can I achieve the same thing with Outlook 2003?

Thanks in advance.

A: 

Do you have to use the OOM at all,could you use System.Net.Mail? if ts just simple mail send. I guess it depends on what else you are doing ?

If not I think you will have to use Extended Mapi and would be in the realms of Librarys like Redemption.

76mel
Unfortunately, System.Net.Mail is not an option in this environment.I'll have a look at Redemption, but at this point it looks like the client might be upgrading to Outlook 2007, in which case this all becomes moot...Thanks.
Reiste
A: 

Sigh... seems I answer more of my own questions on StackOverflow...

Anyway, this is how it's done:

(I think it works for the Outlook Interops 2003 and 2007, and doesn't use Redemption. It may even be how this part of Redemption works, though I haven't looked at that.)

message.PropertyAccessor
    .SetProperty("http://schemas.microsoft.com/mapi/proptag/0x00410102",
    message.PropertyAccessor.StringToBinary(entry.ID));

This schema entry and hex identifier corresponds to the MAPI property PR_SENT_REPRESENTING_ENTRYID. The 'entry' variable was acquired in the code snippet in the question.

Took quite a bit of trawling through the web to find the pieces to make that work. Found that I had to use the PR_SENT_REPRESENTING_ENTRYID property in one place, the fact that 0x00410102 == PR_SENT_REPRESENTING_ENTRYID in another, and the fact that you have to call 'StringToBinary'?... Don't even ask... :) Thanks to the people who had all the pieces posted!

Reiste