Articles: Customizing the Office Ribbon

Just came across the series of articles on Customizing Office Fluent Ribbons for Developers which covers all the customizing options that are available for Developers. Here are their links.

Hope this helps!

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
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
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
MessageBox.Show(“Subject: ” & olRule.Conditions.Subject.Text)
End If
If olRule.Actions.Item(1).ActionType = Outlook.OlRuleActionType.olRuleActionMoveToFolder Then
MessageBox.Show(“Move To Folder: ” & olRule.Actions.MoveToFolder.Folder.FolderPath)
End If
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?


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.


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.


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.

How to get Sender Email Address from MailItem in Exchange Accounts?

For getting Sender Email of a MailItem in POP3/SMTP accounts if pretty easy. We can get that by olMailItem.SenderEmailAddress. But, for Exchange Accounts, its  a bit different. We need to get the AddressEntry first and then get the SMTP Address from that object. Here is a sample code that I framed for simpler understanding.

Dim objSender As Outlook.Recipient = Nothing
Dim objPropXR As Outlook.PropertyAccessor = Nothing
Dim strSMTPAddress As String = “”
Dim strSenderEntryID As String = “”
Dim objNS As Outlook.NameSpace = Nothing
Dim objAE As Outlook.AddressEntry = Nothing
Dim objEU As Outlook.ExchangeUser = Nothing

objNS = Globals.ThisAddIn.Application.GetNamespace(“MAPI”)
objPropXR = objMail.PropertyAccessor
strSenderEntryID = objPropXR.BinaryToString(objPropXR.GetProperty(“”))
objSender = objNS.GetRecipientFromID(strSenderEntryID)
objAE = objSender.AddressEntry
If objAE.AddressEntryUserType = Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry Then
objEU = objAE.GetExchangeUser
strSMTPAddress = objEU.PrimarySmtpAddress
strSMTPAddress = objAE.Address
End If
MessageBox.Show (“Sender Email Address: ” & strSMTPAddress)

objMailItem is an object of Outlook.MailItem

Hope this helps!

How to get accounts from Outlook 2007?

Here is the sample code for getting Account Name and Email Address from Outlook 2007 using VSTO.
Dim olAccounts As Outlook.Accounts = Globals.ThisAddIn.Application.ActiveExplorer().Session.Accounts
Dim acc As Outlook.Account
MessageBox.Show(“No. of accounts: ” & olAccounts.Count.ToString)
If olAccounts.Count > 0 Then
ReDim emails(olAccounts.Count)
For Each acc In olAccounts
MessageBox.Show(“Name: ” & acc.UserName & “Email: ” & acc.SmtpAddress)
MessageBox.Show(“There are no accounts in Outlook”)
End If

Hope this helps!