Tag Archives: Property

Using microsoft graph to Retrieve user by ImmutableId


You can use Microsoft Graph API to access the Azure Active Directory resources. For the given scenario we used the onPremisesImmutableId property to retrieve the user. To test this out, you can use Microsoft Graph Explorer as well and test it by granting the right set of permissions in it.

Here’s the query that i used:

https://graph.microsoft.com/v1.0/users?$filter=onPremisesImmutableId+eq+'{id}’

Microsoft Graph Explorer – snapshot:
image

Hope this helps.

Office Dev: Office 2016 for developers


Last week we announced the release of Office 2016. Next interesting stuff pops in our mind is that what’s new in Office 2016 for the developers. I want to mention few of them here:

– New names for apps for Office and SharePoint – I blogged about this earlier, New name for Apps for Office and SharePoint? Office and SharePoint Add-ins
– Add-in commands for mail – Overview of add-in commands for mail
– Manifest for add-in commands – Create a manifest for add-in commands
– Provides access to properties for Office theme colors – Context.Theme property 

So the next question would be where to get started? Visit http://dev.office.com, check for http://dev.office.com/getting-started/addins and try it out.

In addition, you can refer the Office Dev blog post which talks more about it & make use of it.

Outlook Programming : How to get the SMTP Address of the Sender of a Mail Item using Outlook Object Model?


Recently I was assisting an developer who used Outlook Object Model (OOM) API and tried to get the SMTP address of the Sender of a given mail item.

In order to get the values, he first made the following OOM call – it worked fine for him for couple of mail items, but fails to get the SMTP value as given below:

   1: mailItem.Recipients[i].Address 

It returned the value as,

/O=MFC2013/OU=EXCHANGE ADMINISTRATIVE GROUP (FYDIBOHF23SPDLT)/CN=RECIPIENTS/CN=B370134F8FFD4CF3A0023F27B6B61F7D-ADMINISTRATOR

In this scenario, to determine the SMTP address for a mail item, you can use the SenderEmailAddress property of the MailItem object. However, if the sender is internal to your organization, SenderEmailAddress does not return an SMTP address, and you must use the PropertyAccessor object to return the sender’s SMTP address (adding the related C#.Net code for your reference).

   1: private string GetSMTPAddress(Outlook.MailItem mail)

   2: {

   3:     string PR_SMTP_ADDRESS = @"http://schemas.microsoft.com/mapi/proptag/0x39FE001E";

   4:     if (mail.SenderEmailType == "EX")

   5:     {

   6:         Outlook.AddressEntry sender =

   7:             mail.Sender;

   8:         if (sender != null)

   9:         {

  10:             //Now we have an AddressEntry representing the Sender

  11:             if (sender.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry

  12:                 || sender.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry)

  13:             {

  14:                 //Use the ExchangeUser object PrimarySMTPAddress

  15:                 Outlook.ExchangeUser exchUser = sender.GetExchangeUser();

  16:                 if (exchUser != null)

  17:                 {

  18:                     return exchUser.PrimarySmtpAddress;

  19:                 }

  20:                 else

  21:                 {

  22:                     return null;

  23:                 }

  24:             }

  25:             else

  26:             {

  27:                 return sender.PropertyAccessor.GetProperty(PR_SMTP_ADDRESS) as string;

  28:             }

  29:         }

  30:         else

  31:         {

  32:             return null;

  33:         }

  34:     }

  35:     else

  36:     {

  37:         return mail.SenderEmailAddress;

  38:     }

  39: }

This will help you to move ahead and get the correct SMTP address:

Output

Happy Programming!!

Office Developer: How to programmatically restrict or filter “To” property using Outlook Object Model?


In this post, we will see how to programmatically filter/restrict items “To” property. Let we take this scenario. In Outlook, we notice it contains 6 items “To” property containing “Deva G”:  

Outlook UI

Note:In specifying a filter in a Jet or DASL query, if you use a pair of single quotes to delimit a string that is part of the filter, and the string contains another single quote or apostrophe, then add a single quote as an escape character before the single quote or apostrophe. Use a similar approach if you use a pair of double quotes to delimit a string. If the string contains a double quote, then add a double quote as an escape character before the double quote. For example, in the DASL filter string that filters for the Subject property being equal to the word can't, the entire filter string is delimited by a pair of double quotes, and the embedded string can't is delimited by a pair of single quotes. There are three characters that you need to escape in this filter string: the starting double quote and the ending double quote for the property reference of http://schemas.microsoft.com/mapi/proptag/0x0037001f, and the apostrophe in the value condition for the word can't. Applying the appropriate escape characters, you can express the filter string as follows:

filter = "@SQL=""http://schemas.microsoft.com/mapi/proptag/0x0037001f"" = 'can''t'"

Alternatively, you can use the chr(34) function to represent the double quote (whose ASCII character value is 34) that is used as an escape character. Using the chr(34) substitution for a double-quote escape character, you can express the last example as follows:

filter = "@SQL= " & Chr(34) & "http://schemas.microsoft.com/mapi/proptag/0x0037001f" & Chr(34) & " = " & "'can''t'"

For this above test, first we need to get the property reference for “to” so that we can create DASL Filter for it. For this, you can make use of latest MFC MAPI and get the same using its Property Editor.

MFC MAPI - Property Editor

I am making use of Outlook Object Model (OOM) API to filter/restrict “To” field items containing “Deva G”. In order to do that, you can make use of Items.Restrict method provided in OOM along with the Filter that you want to apply. The Restrict method is significantly faster if there is a large number of items in the collection, especially if only a few items in a large collection are expected to be found.

Filter = "@SQL= " & Chr(34) & "http://schemas.microsoft.com/mapi/proptag/0x0E04001E" & Chr(34) & " = " & "'Deva G'"

Using the above filter, we can build the code using Items.Restrict method – enclosing the Outlook VBA sample for your reference:

'**********************

'Using Items.Restrict

'**********************

 

Public Sub RestrictFilter()

 

Dim myNameSpace As Outlook.NameSpace

Dim myItems As Outlook.Items

Dim currentItem As Outlook.Items

Dim Filter As String

Dim i As Integer

 

Filter = "@SQL= " & Chr(34) & "http://schemas.microsoft.com/mapi/proptag/0x0E04001E" & Chr(34) & " = " & "'Deva G'"

Set myNameSpace = Application.GetNamespace("MAPI")

Set myItems = myNameSpace.PickFolder.Items

Set currentItem = myItems.Restrict(Filter)

For i = currentItem.Count To 1 Step -1

    Debug.Print currentItem(i).Subject

Next

 

End Sub

When you execute the code, you can retrieve the filtered item’s “subject” property values(PR_SUBJECT)….

Outlook VBA - Source code & Output

You can give a try and let me know how it goes…. Happy programming!!

Outlook : How to regenerate free/busy information using MFC MAPI?


Recently one of my customer reported that Outlook is not showing latest free/busy information for selected users.

Initially they tried the following steps for the affected users:
Exit Outlook
Open Command prompt > Open Outlook with cleanfreebusy switch (outlook.exe /cleanfreebusy)
It failed to resolve the issue.  

During troubleshooting we noticed that these issue may occur because a mailbox property does not correctly reference a hidden message in the mailbox, which is related to free/busy publishing.

We tried the below steps for the affected user to re-generate free/busy information:

Exit Outlook.
Make sure that the profile is in online mode. You can change this or create new one using Mail item in Control Panel.
Download latest MFC MAPI editor (http://mfcmapi.codeplex.com)
Start the MFCMAPI.exe >  click OK.  

image

On the Session menu, click Logon.
In the Profile Name list, select the profile for the mailbox, and then click OK.
Double-click the Mailbox Store.
In the navigation pane, click Root Container.

image

In the details pane, right-click PR_FREEBUSY_ENTRYIDS, click Delete Property, and then click OK.
In the navigation pane, expand Root Container, expand Top of Information Store, and then click Inbox.
In the details pane, right-click PR_FREEBUSY_ENTRYIDS, click Delete Property, and then click OK.

image

In the Information Store: Inbox dialog box, click Exit on the File menu.
Exit MFC MAPI.

Finally at Windows, you should click Start, click Run, type outlook.exe /cleanfreebusy, and then press ENTER – this will regenerate the free/busy information for that specific user mailbox.

image

Hope this helps.

MFC MAPI: How to view GAL entries


You can download the latest MFC MAPI utility to view GAL entries, which uses the Messaging API to provide access to MAPI stores through a graphical user interface.

Try the following steps:

1) Open MFC MAPI utility. Select Session menu and select “Logon and Display  Store table” ( I chosen for this session). It will ask you prompt the profile.

image

2) Select the profile. Once you select it, it will open the stores associated with it.

image

3) Select Address Book Menu and select "Open Default Directory” option

image

4) It will list out the GAL entries

image

5) If you select a GAL entry in the top pane, it will display its associated properties, tag, type, value etc in its below pane.

image

Hotfix: Failure Sending mail error with System.Net.Mail (.Net Framework 4.0) while sending large attachment


Recently one of my customer ran into an issue with his application used to send email messages using System.Net.Mail.SmtpClient (SNM) API. He used Visual Studio 2010 and .NET Framework 4.0. It’s a pretty simple code,

//Sample C# code snippet using System.Net.Mail API
SmtpClient MyClient = new SmtpClient("mail_server");
MyClient.Credentials = new System.Net.NetworkCredential("User", "Password", "Domain");
MailMessage MyMsg = new MailMessage("fromuser", "touser", "Testing Attachment", "Testing");
Attachment MyAttachment = new Attachment(@"attachmentfile");
MyMsg .Attachments.Add(MyAttachment );
MyClient.Send(MyMsg );

Using the above code, whenever he adds the attachment size is larger than 3 MB and tries to send the message. It fails with the following a exception System.Net.Mail.SmtpException and error message “Failure sending mail”. Also during troubleshooting i noticed that i generates a inner exception System.IndexOutOfRangeException with the error message “Index was outside the bounds of array”. In the application he also failed to specify the TransferEncoding property of the attachment.

In this customer scenario, recommended him to try with TransferEncoding property with QuotedPrintable worked for him. We tried it like,
MyAttachment.TransferEncoding = System.Net.Mime.TransferEncoding.QuotedPrintable;

You can find the following support knowledgebase article which talks about the issue and provides resolution to overcome the issue. 

Also there is a hotfix available to overcome this issue. Please make sure that you must have .NET Framework 4.0 installed to apply this hotfix. To download this hotfix, you can visit following Microsoft website: https://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=30226.

KB : Outlook Object Model (OOM) limitations


I found this knowledge base article which talks about known limitation you may encounter with the Microsoft Outlook Object model. I found this interesting excerpt, “…unlike other Microsoft Office programs that have “full” object models, such as Microsoft Word and Microsoft Excel, the Outlook object model primarily focuses on items and the folders in which they’re contained. This means that while you can manipulate items, forms, and certain aspects of folders, many of the commands or settings that are available through the user interface are not available when programming. The Outlook object model does not parallel the Outlook user interface..”. Interestingly the above also addresses the one of famous questions which we regularly encounter 🙂

The article also covers the following topics:

  • Changing Option Settings
  • Changing Folder Properties
  • Changing the Mouse Pointer to an Hourglass
  • Changing the Status Bar
  • AdvancedSearch Method

Also you need to note that the scope of this article is limited to using Visual Basic-based programming technologies with the Outlook object model, and may not take into account possible solutions using the Collaborative Data Objects object model or other Microsoft Exchange-related programming technologies.

Outlook 2010 : Outlook Object Model enhancements & Changes


Outlook Object Model Changes

Per Randy’s reference, the Outlook object model has new objects, properties, methods, and events that support new Outlook 2010 features programmatically. Other improvements to the object model address frequent developer requests for specific changes to the Outlook platform.

Outlook Object Model : How to programmatically get logged-in user’s CompanyName in Outlook 2003/2007?


Recently one of my customer updated that they have a requirement to implement the following logic:

1) Get Contact info from GAL or Address book for the specified contact
2) Get Contact information regarding his CompanyName etc.

In the scenario, i provided the following suggestions:

If you try Outlook 2003 & its prior versions: Using the Microsoft Outlook object model, you can access information that is stored in various address books. For example, you can retrieve information about entries in the Global Address Book, or an Outlook Address Book. But if you want to access additional entries that are typically available for a recipient (such as Office, Title or Phone) you can use the Collaboration Data Objects (CDO) object model.

You can try like this CDO code snippet… This code fragment compares the Address property of the Recipient object with the Address and Type properties of its child AddressEntry object, accessible through the recipients AddressEntry property, to demonstrate the relationships between these properties.

    If objOneRecip Is Nothing Then
        MsgBox "must select a recipient"
        Exit Function
    End If
    Set objAddrEntry = objOneRecip.AddressEntry
    If objAddrEntry Is Nothing Then
        MsgBox "no valid AddressEntry for this recipient"
        Exit Function
    End If
 
 
    strMsg = "Recipient full address = " & objOneRecip.Address
    strMsg = strMsg & "; AddressEntry type = " & objAddrEntry.Type
    strMsg = strMsg & "; AddressEntry address = " & objAddrEntry.Address
    MsgBox strMsg ' compare display names
    strMsg = "Recipient name = " & objOneRecip.Name
    strMsg = strMsg & "; AddressEntry name = " & objAddrEntry.Name
 
 

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

For more information about accessing these properties using CDO and detailed information, please see the following articles in the Microsoft Knowledge Base:

HOWTO: Read Address Book Properties in Visual Basic
http://support.microsoft.com/kb/179083/EN-US/

HOWTO: Work with Distribution Lists Using CDO from VB
http://support.microsoft.com/kb/178787/EN-US/

Note: CDO 1.2x/MAPI are not supported in a .NET Framework environment. Refer: http://support.microsoft.com/kb/813349

If you work with Outlook 2007 and later, then you can try using ExchangeUser Object. This object provides first-class access to properties applicable to Exchange users. You can also access other properties specific to the Exchange user that are not exposed in the object model through the PropertyAccessor object.

I tried the VBA code sample and obtain the CompanyName.

Sub GetUserCompany()
 
    Dim oExUser As Outlook.ExchangeUser
 
    'Obtain the AddressEntry for CurrentUser
    Set oExUser = Application.Session.CurrentUser.AddressEntry.GetExchangeUser
 
    MsgBox oExUser.CompanyName
 
 End Sub

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

You need to note that, “some of the explicit built-in properties are read-write properties. Setting these properties requires the code to be running under an appropriate Exchange administrator account; without sufficient permissions, calling the ExchangeUser.Update method will result in a “permission denied” error.”

Hope this helps!! Happy programming & happy holidays!!

Gotcha – PermanentURL & WebDAV Series # 2 – How to access flat URLs using CDO/MAPI


With continuation to previous blog post, this article describes how to access items in a WebDAV application that are identified by using MAPI. The WebDAV application uses flat URLs to access items or folders.

How to use flat URLs to access items by using MAPI ?

  1. Read property tag 0x670E001E by using MAPI on the folder or item to access.

  2. Save the returned value in a variable. The value will resemble the following:

    /-FlatUrlSpace-/ca09cf9efaad754e8a85909b04bb255c-12ee443

  3. Construct a URL that is used to access the folder or item that is using the flat URL. The URL will resemble the following:

    http://server/exchange/mailbox/-FlatUrlSpace-/ca09cf9efaad754e8a85909b04bb255c-12ee443

  4. Use the URL in a WebDAV call to access an item.

Best use of Flat URL usage in the Programming

Flat URLs do not have encoding and escaping rules and will work for folders and items in most DAV operations, with the following exceptions:

  • As destinations of MOVE or COPY operation
  • As a source for a DELETE
  • For Outlook Web Access URL commands; for example, ?cmd=[myCommand].

Use this property when you are stepping out of CDO 1.2.1 or MAPI code into WebDAV. The HREF in WebDAV is usually created from the subject that was typed in Microsoft Outlook. The subject in Outlook can contain characters that are encoded for use with DAV. This encoding resembles URL encoding. Instead of reverse engineering the encoding, use the flat URL to get the item.

Hope this helps.