Outlook Redemption library - Accessing shared mailboxes / specific folders with a service account - c#

I’m converting an existing piece of code using Redemption (an MS Exchange library) to operate under a service account. The issue I’m having is that I’m unable to look up mail folders as I previously was.
The first hurdle in moving to a service account was overcome by switching
_rdoSession.Logon() // <- Which uses the account’s MAPI profile, and throws an exception under a service account
To:
_rdoSession.LogonExchangeMailbox("", "mailserver.example.com");
The problem comes with trying to access specific folders. Previously I was able to use:
_session.GetFolderFromPath("\\\\Mailbox - Example shared mailbox\\Inbox\\FolderOne");
_session.GetFolderFromPath("\\\\Mailbox - Example shared mailbox\\Inbox\\FolderTwo");
Under a service account, I can’t address shared mail accounts with that same syntax, as I get the error:
Could not open store "Mailbox – Example shared mailbox": Error in IMAPITable.FindRow: MAPI_E_NOT_FOUND
Some Googling has shown the beginning step is to use:
_session.Stores.GetSharedMailbox("Example shared mailbox ")
I've verified this returns the correct shared mailbox object.
However - from there, there are no search methods. I can try my luck with building new code to navigate the folder structure from the .RootFolder property, but this seems like a hack.
How should I be accessing specific folders in a shared mailbox, run under a service account in Redemption?

You can use either
store = _session.Stores.GetSharedMailbox("Example shared mailbox ");
folder = store.IPMRootFolder.Folders.Item("Inbox").Folders.Item("FolderTwo");
or
store = _session.Stores.GetSharedMailbox("Example shared mailbox ");
folder = store.GetDefaultFolder(olFolderInbox).Folders.Item("FolderTwo");

Related

Locate all .pst files

Greetings
I have a problem with locating .pst files. **
The task
** is to find all .pst files on a machine and create a list of them.
I tried to use Registry entry: "HKCU\Software\Microsoft\Office\%OfficeVersion%\Outlook\Search\Catalog". Looks like it contains list of all .pst & .ost files, but turned out it also has entries of deleted(or moved) files and it updates only if you connect .pst manually in Outlook. So if you move your old .pst in some kind of "Archive" my registry will not contain info about it.
I understand that looking through all files takes too much time, so I want to avoid that.
Also, keep in mind that user might have a lot of mailboxes and a lot of .pst(some of them might not even be connected to Outlook at all). And I can't use such things as Redemption or anything. Just plain C#(may be some C++ MAPI lib)
Thanks a lot.
The PST file locations is stored in the profile sections in the registry. The officially supported API designed to access and manipulate the profile data is the IProfAdmin interface (you can play with it in OutlookSpy (I am its author) if you click the IProfAdmin button). PST path is stored in the PR_PST_PATH property. Extended MAPI can only be accessed from C++ or Delphi.
The profile data is stored in the registry, so in theory you could read the data from the registry, but the key names are profile specific and are generated randomly (profile section name is a guid). Also note that the profile data location in the registry is Outlook version specific.
You can use ProfMan (it comes with the distributable version of Redemption); ProfMan can be used from any language. The following script (VB) retrieves PST files names from all local profiles:
'Print the path to all the PST files in all profiles
PR_PST_PATH = &H6700001E
set Profiles=CreateObject("ProfMan.Profiles")
for i = 1 to Profiles.Count
set Profile = Profiles.Item(i)
set Services = Profile.Services
Debug.Print "------ Profile: " & Profile.Name & " ------"
for j = 1 to Services.Count
set Service = Services.Item(j)
If (Service.ServiceName = "MSPST MS") or (Service.ServiceName = "MSUPST MS") Then
MsgBox Service.Providers.Item(1).ProfSect.Item(PR_PST_PATH)
End If
next
next
You can also retrieve PST file names from PST stores using the Outlook Object Model (but that requires Outlook to be running, and you can only do that for the currently used profile) - use the Store.FilePath property:
set vApp = CreateObject("Outlook.Application")
for each vStore in vApp.Session.Stores
MsgBox vStore.DisplayName & " - " & vStore.FilePath
next

TFS Error when writing logs to drop location: "The user name or password is incorrect."

I've used Azure File storage to configure a shared storage space that my Build Server has access to - https://azure.microsoft.com/en-us/blog/azure-file-storage-now-generally-available/
I used the following command to attach the space:
net use Z: \\portalxyz.file.core.windows.net\drops /u:portalxyz abcdef==
This works on both my Azure VMs (Build server included, with agents on it) and my local machine - I can see the drive and read/write to it.
However when I attempt a build after setting the drop location (in the build definition) to this share \\portalxyz.file.core.windows.net\drops, I get the following:
Exception Message: The user name or password is incorrect.
Looking at the exception details in the Event Log on the server, I can see that a service user is being used. I've logged into the machine as that user and mapped the space using the above command, but the error persists.
What am I doing wrong?
You Build Server needs to have the storage account key to access the Azure file share,
There are two options to achieve this
1) Create a system/service account using your Azure storage account name and key and then run the build server with this account
2) Use CMDKey to persistent the credential under current user context (refer to this blog for details)
To Set up a drop folder on a file share for your on-premises build controllers
You must be a member of the Administrators group on the computer where the drop folder resides.
More info about how to set up a drop folder on a file share from MSDN.

Outlook API GetItemFromID() fails with error "Could not open the item.Try again." when using multiple outlook accounts

I am using two outlook accounts from the same exchange server (i.e. same domain). We have an outlook add-in which we use to archive some emails from outlook to an external web application. While composing a new mail, it's possible to attach some files from external application to the mail being composed using the add-in.
Now things work perfectly when I have a single account on outlook. But after configuring another account and trying to do the same from secondary account, outlook gives error:
Outlook Initiator exception:
System.Runtime.InteropServices.COMException (0x80040107): Could not
open the item. Try again. at
Microsoft.Office.Interop.Outlook.NameSpaceClass.GetItemFromID(String
EntryIDItem, Object EntryIDStore)
I tried to dig into the code and found that the call to GetItemFromID() gives the exception shown above.
object item = ns.GetItemFromID(objectID, storeId);
The first parameter objectID (which is EntryIDItem) is different for different accounts but second parameter storeId is same.
I also tried to see the body of the method GetItemFromID() using disassembler but the method is defined as an extern method that means it's defined outside of the current assembly as un-managed code.
Tried to search for anything similar to that on stackoverflow but no luck. Can anybody please help me on this?
Try to leave only the first parameter. The EntryIDStore parameter is optional. See NameSpace.GetItemFromID for more information.
Note, the Entry ID changes when an item is moved into another store, for example, from your Inbox to a Microsoft Exchange Server public folder, or from one Personal Folders (.pst) file to another .pst file. Solutions should not depend on the EntryID property to be unique unless items will not be moved.

Creating an Exchange Mailbox for a User in C#

I just created a user in Active Directory. I would like to create an exchange mailbox for this user. Can I just set some of the users properties? Something like this:
DirectoryEntry user = ...Get the user
user.Properties["someProerty"] = "someValue";
user.CommitChanges();
Where someProperty and someValue are what is needed to create a mailbox?
Is there documentation on how to do this? Could you tell me what properties need set?
No, an exchange mailbox is more than just properties on an LDAP entry. You'll actually need to work with Exchange directly to accomplish this. If you are using Exchange 2007+ you can use the New-Mailbox PowerShell commandlet.
In one of my previous jobs, I installed the Exchange Management Tools on my web server and automated creating a PowerShell runtime environment to execute the necessary commandlets. Once you execute the right commands the attributes (such as mailbox, email, etc.) will be added by Exchange.
You can create a PowerShell runtime environment by creating a runspace.
http://support.microsoft.com/kb/313114 perhaps.
There is tons of documentation on these things, try google ;)
For 2007 exchange try this http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/thread/4cd5ea2e-5967-42f2-a503-f1e031a1b393/
No You have to use powershell cmdlet to change some properties of mailBox .For Example You can not change Alias Name with the help of Active Directory Cmdlets.I am also new and this is just my experience.hope this will be helpfull to you.

Exchange WS 'The specified object was not found in the store.' error

We're using Exchange 2007 WS to process mail folders and are hitting various problems if we try and forward a message we've already received. Our process is:
Windows Service monitors mailbox folder, on finding a new mail we process the information and move the item to a 'Processed folder' and store the Exchange Message Id.
Users may opt to forward the mail externally. We use the Exchange API to find the item using the Message Id we stored earlier, and then again use the API to forward.
Except finding the mail again is proving rather flaky. We regularly get the following error:
The specified object was not found in the store.
Is there a better/more reliable way we can achieve the same? The documentation for Exchange WS is rather sparse.
This is a bug in microsoft exchange manage API. here is a link for more information
http://maheshde.blogspot.com/2010/09/exchange-web-service-specified-object.html
Are you saving the Message ID of the newly found message or the message once it has been moved to the 'Processed' folder? The id will change when it moves to a new folder.
The method recommended in the book Inside Microsoft Exchange Server 2007 Web Services is to grab the PR_SEARCH_KEY (0x300B, Binary) of the newly discovered item, then move it to the 'Processed' folder. You can then search for it in the new folder based on the PR_SEARCH_KEY and get it's new Message id to forward it.
I have come to the conclusion that this happens to me is because while my app is processing the emails, someone else is fiddling with an email at the same time.
So to cure the problem, I put it the code in a try catch and see if the exception is == the that object not found in store, if so I just skip it and move on to the next item. So for has no issues.
I wrote a program that reads the emails in inbox downloads attachments to the specified folder, wrote the email info and the saved path to the database, and finally deletes the email. I run this program as a windows service. After all tests are finished I run this program to the main server and run it. Program runs successfully but sometimes I got this error. I checked everything and finally I found that I forgot to stop service on my computer. 2 programs that runs on my computer and on real server checking the same mailbox at the same time. If you get this error make sure that only one program can process at the same mailbox.

Categories

Resources