none
how to get the e-mail address for the current folder

    Question

  • Hi,

    I have a case where i (in a VSTO add-in) need to retrieve the smtp-address for a folder. The mailitem can be either in the primary exchange mailbox or a shared mailbox.

    What i have tried is using the Accounts collection and compare the storeid but the problem with that approach is that it doesn't work for shared mailboxes because the shared mailbox aren't in the accounts collection also I have an account for "Live meeting" which also matches the same Store ID and that's not the account which I want (I solved that by checking that the SMTPAdress is not null).

    Using Outlook spy I have found one property PR_STORE_ENTRY_ID which has this value in a somewhat interesting form - binary - and outlook spy is able to decode this but I'm not sure if this property can be decoded and used for this purpose.

    Please advice.

    Tuesday, February 28, 2012 1:58 PM

Answers

  • Take a MAPI viewer such as MFCMAPI or OutlookSpy and look at all the properties of a store or a folder and tell me if you see any property that provides what you want. You won't see it.
     
    You'd see PR_DISPLAY_NAME_W for the store display name. That's about it.
     
    The store doesn't determine the sending address necessarily. If I reply to an item in my Sales mailbox it would go out from "kens", unless I choose to send it as "sales". I have SendAs permissions on the Sales mailbox. If I log in as "kens" I can send as "sales" or as "kens", if i log in as "Sales" I can only send as "sales".
     
    What we used to do was to take the StoreID value and convert it into text from hex ASCII. In that you'd see the Exchange DN for that store. So in my Exchange server mailbox I'd see something like this as part of StoreID:
    THANE /o=SLOVAKTECH/ou=first administrative group/cn=Recipients/cn=KenS
     
    Where KenS is the Exchange alias and the other pieces are all part of the Exchange DN.
     
    In my Sales mailbox, Store ID would have something like this as part of it:
     
    THANE /o=SLOVAKTECH/ou=first administrative group/cn=Recipients/cn=Sales
     
    And in my dog's mailbox it would look like this:
     
    THANE /o=SLOVAKTECH/ou=first administrative group/cn=Recipients/cn=CaseyS
     
    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Membrane" <=?utf-8?B?TWVtYnJhbmU=?=> wrote in message news:5d14dbfd-7394-4fef-b39c-bcb8380bf4ee...

    Hi Ken,

    the storedisplayname is just a visual thingie isn't it?

    In the end shouldn't a store always have some way of getting it's associated mailbox-address? I mean, when I for example send a mail from a shared mailbox (which as you say has a unique store id) that mailbox also has a unique e-mail-adress (smtp-address) which is added in the from-field of that e-mail and that address is retrieved from somewhere..?



    Ken Slovak MVP - Outlook
    • Marked as answer by Membrane Wednesday, February 29, 2012 9:33 AM
    Tuesday, February 28, 2012 7:38 PM

All replies

  • StoreID is a GUID that is used to identify an Outlook store (mailbox or PST file usually). Using the NameSpace.GetStoreFromID() method allows you to return a Store object from that property.
     
    In the Outlook object model StoreID is a hex encoded string value, in MAPI terms it's a PT_BINARY property that consists of an array of binary characters.
     
    I'm not sure however what you mean by an SMTP address for a folder. In general a folder such as Inbox in a store isn't mail enabled and you can't send emails directly to a specific folder, as you can for a public folder where if a folder is mail enabled it could directly receive emails.
     
    Please explain clearly exactly what you are trying to do and what you are trying to identify.
     
    An Outlook profile can have one or more email accounts set up, or none. That same profile can open one or more stores such as mailboxes, public folders, delegate mailboxes, PST files, and so on. The same store can be opened in multiple profiles and some may or may not have email addresses.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Membrane" <=?utf-8?B?TWVtYnJhbmU=?=> wrote in message news:8906f420-eeee-48c5-a8d5-05a283edbbe6...

    Hi,

    I have a case where i (in a VSTO add-in) need to retrieve the smtp-address for a folder. The mailitem can be either in the primary exchange mailbox or a shared mailbox.

    What i have tried is using the Accounts collection and compare the storeid but the problem with that approach is that it doesn't work for shared mailboxes because the shared mailbox aren't in the accounts collection also I have an account for "Live meeting" which also matches the same Store ID and that's not the account which I want (I solved that by checking that the SMTPAdress is not null).

    Using Outlook spy I have found one property PR_STORE_ENTRY_ID which has this value in a somewhat interesting form - binary - and outlook spy is able to decode this but I'm not sure if this property can be decoded and used for this purpose.

    Please advice.


    Ken Slovak MVP - Outlook
    Tuesday, February 28, 2012 3:37 PM
  • Hi Ken

    thanks for reply,

    Say I In my outlook have my Primary Mailbox associated with my user and a shared mailbox as well.

    Now for any MailItem I select - when I press a button I want to retrieve the mail adress (smtp-address) for that mailbox.

    Tuesday, February 28, 2012 5:01 PM
  • I'm sorry, I still don't follow.
     
    If you select an item it will have been sent by some address or received by some address, but the folder it's in doesn't have a specific email address.
     
    I can move an item from one mailbox to another and it doesn't change anything related to email addresses. I can move items from mailboxes to PST files and back again and it still won't change anything related to SMTP addresses on the item.
     
    Say I have a mailbox named "sales" and a primary mailbox for an alias of "kens". I can get the Store.DisplayName, which would be either "sales" or ("kens" + my domain). Neither is a fully formed SMTP address. In the case of Outlook 2010 only the "kens" mailbox display name would include the domain, but that isn't the case in delegate mailboxes.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Membrane" <=?utf-8?B?TWVtYnJhbmU=?=> wrote in message news:3ab8b111-0243-4292-a697-f50a8e746eb1...

    Hi Ken

    thanks for reply,

    Say I In my outlook have my Primary Mailbox associated with my user and a shared mailbox as well.

    Now for any MailItem I select - when I press a button I want to retrieve the mail adress (smtp-address) for that mailbox.


    Ken Slovak MVP - Outlook
    Tuesday, February 28, 2012 5:12 PM
  • Hi Ken,

    say your primary exchange adress is ken@slovak.mvp you also have a shared mailbox in outlook which is info@slovak.mvp, now, let's say you drag a mail item from your primary mailbox (ken@) to info@ (just to make the issue clearer).

    Lets say you then select this e-mail (which is now in info@) is it possible to somehow retrieve the fact that this mailitem is now residing somewhere in the mailbox which is associated with an smtpaddress of info@slovak.mvp ?

    The bigger issue at hand is I'm trying to create a tool for moving e-mails between mailboxes using Exchange Web Services API, and for that to work the API needs to know which Mailbox to look in (specified by smtpadddress) to find the mailitem which is to be moved to another mailbox.

    Tuesday, February 28, 2012 6:17 PM
  • What you want is not an SMTP address. It's the StoreID, as I mentioned previously. When you drag the item from mailbox A to mailbox B the StoreID changes. Other properties also would change, but StoreID identifies where the item is now stored.
     
    SMTP address is meaningless, and you wouldn't even have that as part of a store display name for versions of Outlook earlier than 2010. A mailbox in Outlook 2007 would just be "Ken Slovak" or "Sales" it's only in 2010 that it would also include an SMTP address as part of the display name.
     
    As far as what you'd need for a tool to use with EWS, that you should post in an EWS forum and not one for Outlook programming. http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/threads is an Exchange development forum that takes EWS questions. The people there would be a lot more familiar with using EWS.
    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Membrane" <=?utf-8?B?TWVtYnJhbmU=?=> wrote in message news:fc9ce4e4-77ef-434b-b643-5a46ac4209eb...

    Hi Ken,

    say your primary exchange adress is ken@slovak.mvp you also have a shared mailbox in outlook which is info@slovak.mvp, now, let's say you drag a mail item from your primary mailbox (ken@) to info@ (just to make the issue clearer).

    Lets say you then select this e-mail (which is now in info@) is it possible to somehow retrieve the fact that this mailitem is now residing somewhere in the mailbox which is associated with an smtpaddress of info@slovak.mvp ?

    The bigger issue at hand is I'm trying to create a tool for moving e-mails between mailboxes using Exchange Web Services API, and for that to work the API needs to know which Mailbox to look in (specified by smtpadddress) to find the mailitem which is to be moved to another mailbox.


    Ken Slovak MVP - Outlook
    Tuesday, February 28, 2012 6:39 PM
  • Hi Ken,

    the storedisplayname is just a visual thingie isn't it?

    In the end shouldn't a store always have some way of getting it's associated mailbox-address? I mean, when I for example send a mail from a shared mailbox (which as you say has a unique store id) that mailbox also has a unique e-mail-adress (smtp-address) which is added in the from-field of that e-mail and that address is retrieved from somewhere..?


    Tuesday, February 28, 2012 7:14 PM
  • Take a MAPI viewer such as MFCMAPI or OutlookSpy and look at all the properties of a store or a folder and tell me if you see any property that provides what you want. You won't see it.
     
    You'd see PR_DISPLAY_NAME_W for the store display name. That's about it.
     
    The store doesn't determine the sending address necessarily. If I reply to an item in my Sales mailbox it would go out from "kens", unless I choose to send it as "sales". I have SendAs permissions on the Sales mailbox. If I log in as "kens" I can send as "sales" or as "kens", if i log in as "Sales" I can only send as "sales".
     
    What we used to do was to take the StoreID value and convert it into text from hex ASCII. In that you'd see the Exchange DN for that store. So in my Exchange server mailbox I'd see something like this as part of StoreID:
    THANE /o=SLOVAKTECH/ou=first administrative group/cn=Recipients/cn=KenS
     
    Where KenS is the Exchange alias and the other pieces are all part of the Exchange DN.
     
    In my Sales mailbox, Store ID would have something like this as part of it:
     
    THANE /o=SLOVAKTECH/ou=first administrative group/cn=Recipients/cn=Sales
     
    And in my dog's mailbox it would look like this:
     
    THANE /o=SLOVAKTECH/ou=first administrative group/cn=Recipients/cn=CaseyS
     
    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Membrane" <=?utf-8?B?TWVtYnJhbmU=?=> wrote in message news:5d14dbfd-7394-4fef-b39c-bcb8380bf4ee...

    Hi Ken,

    the storedisplayname is just a visual thingie isn't it?

    In the end shouldn't a store always have some way of getting it's associated mailbox-address? I mean, when I for example send a mail from a shared mailbox (which as you say has a unique store id) that mailbox also has a unique e-mail-adress (smtp-address) which is added in the from-field of that e-mail and that address is retrieved from somewhere..?



    Ken Slovak MVP - Outlook
    • Marked as answer by Membrane Wednesday, February 29, 2012 9:33 AM
    Tuesday, February 28, 2012 7:38 PM
  • Hi Ken,

    the behavior you're describing is a little bit different from what i've experienced. In my experience, whenever i try to reply to an e-mail which is in a shared mailbox the from-address is set to the shared mailbox address. 

    as for the outlook spy, i intially wrote about the PR_STORE_ENTRY_ID, in that property when looking using outlook spy, i was able to see the exchange-dn field which you are describing.

    Could it perhaps be possible to decode in a way similar to what you described and convert exchange-dn into an e-mail address that I desire?

    Tuesday, February 28, 2012 7:52 PM
  • How the sending address is added and whether or not you can change that is a function of mailbox ownership, SendAs permissions, delegate permissions and possibly the phases of the moon <g>
     
    In my EX server, where I'm every sort of admin and have direct or indirect ownership of just about every mailbox I can set the sending address to whatever I want. If I log in to Outlook as my dog, who's and Exchange admin but doesn't have mailbox ownership of every mailbox I can't set the sending address except as him or the mailbox.
     
    I mentioned the hack of StoreID for the reason you mention, it does provide a possible way for you to get what you're looking for. You'd still need to get the domain to add to the EX alias, but you could try it and see if does what you need.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "Membrane" <=?utf-8?B?TWVtYnJhbmU=?=> wrote in message news:5eabe22c-7e59-44e3-ac5b-7040137eef7c...

    Hi Ken,

    the behavior you're describing is a little bit different from what i've experienced. In my experience, whenever i try to reply to an e-mail which is in a shared mailbox the from-address is set to the shared mailbox address. 

    as for the outlook spy, i intially wrote about the PR_STORE_ENTRY_ID, in that property when looking using outlook spy, i was able to see the exchange-dn field which you are describing.

    Could it perhaps be possible to decode in a way similar to what you described and convert exchange-dn into an e-mail address that I desire?


    Ken Slovak MVP - Outlook
    Tuesday, February 28, 2012 7:59 PM
  • Hi Ken, 

    I managed to solve this using the PR_STORE_ENTRY property, thanks alot for the help :-)

    Wednesday, February 29, 2012 9:33 AM