Getting Rules from an exchange account in Outlook

Getting Rules from an exchange account configured in Outlook is pretty easy though many developers who is working on it for the first time may confuse with the approach. I banged my head for 2 days to get the exact function and attributes to get them.

Dim olRules As Outlook.Rules = Globals.ThisAddIn.Application.Session.DefaultStore.GetRules

For Each olRule As Outlook.Rule In olRules
If olRule.Conditions.From.Recipients.Count > 0 Then
‘ CONDITION: FROM EMAIL
Dim exUser As Outlook.ExchangeUser = olRule.Conditions.From.Recipients.Item(1).AddressEntry.GetExchangeUser
Dim FromEmail As String = exUser.PrimarySmtpAddress
MessageBox.Show(“FROM:  ” & FromEmail)
ElseIf olRule.Conditions.SentTo.Enabled Then
‘ CONDITION: TO EMAIL
Dim exUser As Outlook.ExchangeUser = olRule.Conditions.To.Recipients.Item(1).AddressEntry.GetExchangeUser
Dim ToEmail As String = exUser.PrimarySmtpAddress
MessageBox.Show(“TO: ” & ToEmail)
ElseIf olRule.Conditions.Subject.Enabled Then
‘ CONDITION: SUBJECT
MessageBox.Show(“Subject: ” & olRule.Conditions.Subject.Text)
End If
‘ ACTION: MOVE TO FOLDER
If olRule.Actions.Item(1).ActionType = Outlook.OlRuleActionType.olRuleActionMoveToFolder Then
MessageBox.Show(“Move To Folder: ” & olRule.Actions.MoveToFolder.Folder.FolderPath)
End If
Next
Hope this Helps!

Getting To, Cc and BCc email addresses from a MailItem in Outlook

Seems to be a simple task. Right? But, not exactly.

Say olMailItem is the object of Outlook.MailItem. From olMailItem.TO, olMailItem.CC and olMailItem.BCC, we get the names of the recipients from the Outlook contacts. But not their email addresses.

To get email addresses, we can use the following code.

Dim olRecipients As Outlook.Recipients

olRecipients = olMailItem.Recipients

Dim strToEmails, strCcEmails, strBCcEmails As String

For Each olRecipient As Outlook.Recipient In olRecipients

If olRecipient.Type = Outlook.OlMailRecipientType.olTo Then

strToEmails += olRecipient.Address & vbCrLf

ElseIf olRecipient.Type = Outlook.OlMailRecipientType.olCC Then

strCcEmails += olRecipient.Address & vbCrLf

ElseIf olRecipient.Type = Outlook.OlMailRecipientType.olBCC Then

strBCcEmails += olRecipient.Address & vbCrLf

End If

Next

MessageBox.Show(“To: ” & strToEmails & “Cc: ” & strCcEmails & “BCc: ” & strBCcEmails)

Hope this helps!

Common mistakes while installation and deployment of PIAs

Have you ever came across this error message while deploying PIAs along with your add-in as prerequisites?

Problem:

Error 1316: Setup cannot read from file {PATH}\PIARedist.MSI. Check your connection to the network, or CD-ROM drive. For other potential solutions, see SETUP.CHM.

Reason:

This error occurs if the PIA’s already installed in the client system. This usually happens with Office 2007 if Outlook is installed with Contact Manager.

Business Contact Manager for Outlook 2007 installs the PIAs by default, and the file name is PIARedist.MSI.  However, the file from the Microsoft Download Center is called o2007pia.msi.  When you install the PIAs from the Microsoft Download Center, this name conflict causes the 1316 error.

Solution:

The simplest solution is to just ignore the error, because this message means that the PIAs are already installed. If you want to correct the error, uninstall the PIAs through the list of installed programs for the specific computer. Then you can reinstall the PIAs with the Primary Interop Assemblies for the 2007 Microsoft Office system from the Microsoft Download Center.

For more details, refer to Misha’s article in her blog.

http://blogs.msdn.com/b/vsto/archive/2008/05/20/common-pitfalls-during-pia-deployment-and-installation.aspx

Including Custom Prerequisites in a Setup Project to install Hot Fix

Today I came across a discussion that is going on in MSDN Forums on the topic “How to check for a Microsoft Hot Fix in the client system and install if it is not installed in it?”. After going through the threads and reading few articles on this, I would like to share a quick work-around  for this problem which might help someone who is facing the same problem.

Briefly, the solution is to create a bootstrapper package for the required Hot Fix and use it as prerequisite in the Setup Project

We can create the bootstrapper using a tool called “Bootstrapper Manifest Generator” (BMG). This can be downloaded (free) from the following location.

http://code.msdn.microsoft.com/bmg

We can check registry to confirm whether the Hot Fix is installed or not. We need to set several Bypass-if conditions to make sure that we install the Hot Fix only when it is particular version of OS and the Hot Fix has not been installed.

* Usually Hot Fixes are Operating System specific

Here are some useful links related to this topic.

http://social.msdn.microsoft.com/forums/en-us/winformssetup/thread/58E75C92-4689-487E-9FF7-8835246B82FA

http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/a4e2a6af-c3ea-4b7a-9348-7dfa6a6164dd

Setting up bootstrapper package of Microsoft Office Primary Interop Assemblies (PIA) to use as prerequisite for setup project

This is the procedure to set Office Primary Interop Assemblies as prerequisites to your setup project.

First, You need to download the sample of component checker sample (ComponentChecker.cpp) from this MSDN page. http://msdn.microsoft.com/en-us/library/bb332051(office.12).aspx

Please go through “Preparing the Office Component Check” section in this article. Then follow these steps.

  1. Open the Command Prompt window needed to compile the check.If you are using Visual Studio 2008, open the Visual Studio 2008 Command Prompt by clicking Start, and then pointing to Programs, pointing to Microsoft Visual Studio 2008, pointing to Visual Studio Tools, and then clicking Visual Studio 2008 Command Prompt.
  2. At the command prompt, change the directory to {SamplesDir}\projects\Checks

    By default, the SamplesDir directory is C:\Program Files\Microsoft Visual Studio 2005 Tools for Office SE Resources\VSTO2005SE Windows Installer Sample Version 3\.

  3. Compile the component checker by typing the following command
    cl.exe /Oxs /MT /GS ComponentCheck.cpp advapi32.lib
  4. Close the Command Prompt window.
  5. Using Windows Explorer, copy the executable file ComponentCheck.exe into {SamplesDir}\packages\Office2003PIA and {SamplesDir}\packages\Office2007PIA.

To prepare the primary interop assemblies bootstrapper package, follow these steps.

  1. Download Office 2003 Update: Redistributable Primary Interop Assemblies from the Microsoft Download Center.
  2. Run the primary interop assembly installer.
  3. Accept the Microsoft Software License Terms, which gives you the right to package the primary interop assemblies as part of your installer.
  4. In Windows Explorer, open the folder to which the installer extracted the files.
  5. Copy O2003PIA.msi into the directory {SamplesDir}\packages\Office2003PIA

For more details, go through these:

http://msdn.microsoft.com/en-us/library/bb332051(office.12).aspx

http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/cd733f1a-7db3-430d-9700-92dc7bdac077/?prof=required

Hope this helps!