Welcome to MSDN Blogs Sign in | Join | Help

How to get Extended MAPI Properties in the GetItem Exchange Web Service call?

We can get/set Extended MAPI Properties using Exchange Web Services for Exchange Server 2007/2010.

Here is sample code snippet to get value for CleanGlobalObjectID via GetItem call of Exchange Web Services:

NOTE: Following programming examples is for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This sample code assumes that you are familiar with the programming language being demonstrated and the tools used
to create and debug procedures.

private void fnGetCalItem()
        {
            // Form the GetItem request
            GetItemType getRequest = new GetItemType();
 
            // Define which item properties are returned in the response
            ItemResponseShapeType itemProperties = new ItemResponseShapeType();
            itemProperties.BaseShape = DefaultShapeNamesType.AllProperties;
 
            // Add properties shape to request
            getRequest.ItemShape = itemProperties;
 
            // Set the itemID of the desired item to retrieve
            ItemIdType id = new ItemIdType();
            id.Id = itemID;
            getRequest.ItemIds = new ItemIdType[] { id };
 
 
            PathToExtendedFieldType[] pteft = new PathToExtendedFieldType[1];
 
            pteft[0] = new PathToExtendedFieldType();
            
            //Add CleanGlobalObjectID extended property 
            pteft[0].PropertyId = 35;
            pteft[0].PropertyIdSpecified = true;
            pteft[0].PropertySetId  = "6ED8DA90-450B-101B-98DA-00AA003F1305" ; 
            pteft[0].PropertyType = MapiPropertyTypeType.Binary;
            itemProperties.AdditionalProperties = pteft;
 
            // Send the listing (find) request and get the response
            GetItemResponseType getResp = binding.GetItem(getRequest);
 
            // Get the response message
            if (getResp.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Success)
            {
                ItemInfoResponseMessageType iirmt = getResp.ResponseMessages.Items[0] as ItemInfoResponseMessageType;
                itemGCOID = iirmt.Items.Items[0].ExtendedProperty[0].Item.ToString() ;
             }
            else
            {
                Console.WriteLine(getResp.ResponseMessages.Items[0]);
            }
        }

 

Articles referenced for the above sample code:

Hope this helps!

How to deploy VSTO add-ins for Outlook?

“What is the best way to deploy VSTO add-ins for Outlook?” This is one of the most common question asked by our customers who are developing add-ins using Visual Studio Tools for Office(VSTO) for Outlook and other Office Applications.  Simple answer is that it’s all depend on you requirements and environment. We can opt for either ClickOnce Deployment or Windows Installer.

We can refer to Choosing a Deployment Strategy and the following table compares the features of ClickOnce deployment with Windows Installer deployment to make informed decision:

Features

ClickOnce

Windows Installer

Automatic update1

Yes

Yes

Post-installation rollback2

Yes

No

Update from Web

Yes

No

Does not affect shared components or other applications

Yes

No

Security permissions granted

Grants only permissions necessary for the application (more safe)

Grants Full Trust by default (less safe)

Security permissions required

Internet or Intranet Zone (Full Trust for CD-ROM installation)

Administrator

Application and deployment manifest signing

Yes

No

Installation-time user interface

Single prompt

Multipart Wizard

Installation of assemblies on demand

Yes

No

Installation of shared files

No

Yes

Installation of drivers

No

Yes (with custom actions)

Installation to Global Assembly Cache

No

Yes

Installation for multiple users

No

Yes

Add application to Start menu

Yes

Yes

Add application to Startup group

No

Yes

Add application to Favorites menu

No

Yes

Register file types

Yes

Yes

Install time registry access3

Limited

Yes

Binary file patching

No

Yes

Application installation location

ClickOnce application cache

Program Files folder

Articles to refer

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Notes:

1. With Windows Installer, you must implement programmatic updates in the application code.

2. With ClickOnce, rollback is available in Add or Remove Programs.

3. ClickOnce deployment can access HKEY_LOCAL_MACHINE (HKLM) only with Full Trust permission.

Feel free to put questions related to ClickOnce or Windows Installer deployment for Office Add-ins to me.

Exchange Web Services and Exchange 2010 - What’s new Webcasts

Exchange 2010 is on it way and along with it Exchange Web Services Managed API would be one-in-all interface for developing custom applications.

So, If you are developing Exchange related application and interested to know what you can do with the new EWS Managed API and what’s new in Exchange 2010 for developers then, Here are few interesting web casts to learn more: 

10/13/2009 - Exchange Server 2010 Development (Part 1 of 6): Migrating Applications to Exchange Web Services

10/14/2009 - Exchange Server 2010 Development (Part 2 of 6): A Deep Dive into Using Autodiscover Service in Exchange Web Services

10/15/2009 - Exchange Server 2010 Development (Part 3 of 6): A Deep Dive into Impersonation and Delegation in Exchange Web Services

10/20/2009 - Exchange Server 2010 Development (Part 4 of 6): A Deep Dive into Exchange Web Services Notifications (Push/Pull)

10/21/2009 - Exchange Server 2010 Development (Part 5 of 6): A Deep Dive into the Exchange Web Services Managed API

10/22/2009 - Exchange Server 2010 Development (Part 6 of 6): Best Practices for Building Scalable Exchange Server Applications

If you can’t wait for it, then have a sneak peek from quick video with Jason Henderson and David Claux of the EWS team @ Chris Mayo’s post.

Enjoy!!!

How to create a Service Account with full access to all mailboxes on Exchange Server 2007 mailboxstore?

We can use following Exchange PowerShell cmdlet to grant a Service Account full access to all the mailboxes on Exchange Server 2007 mailboxstore, but do so only in accordance with your organization's security and privacy policies:

Get-mailboxserver <servername> | add-adpermission –user <service account> -accessrights GenericRead, 
GenericWrite -extendedrights Send-As, Receive-As, ms-Exch-Store-Admin

We need to modify <servername> as the Exchange Server name and <service account> as the account for which we would like to grant access.

If you have further questions related to Exchange 2007 Permissions then please refer to
Exchange 2007 Permissions: Frequently Asked Questions

And if you writing a custom application using EWS or Exchange Web Services Managed API for Exchange 2007 then you can also have look at nice post @ Exchange Impersonation vs Delegate Access. which explain difference between Exchange Impersonation and  Delegate Access to access an Exchange mailbox using Exchange Web Services.

Exchange 2007 Webcasts for Client Access and Web Services

Want to learn more about Microsoft Exchange Server 2007 then Support WebCasts  are way to go. Support Webcasts are a free Internet broadcast service that is provided by Microsoft. You can view webcasts on-demand, and you can also download them in Microsoft Windows Media format for offline viewing.

Here are few worthy of note webcasts which I found for the Exchange developers:

Join us for a look at the various underlying components of Exchange Server 2007 Client Access Services. We cover the enhanced calendar functionality, the new Unified Messaging and Exchange Server Web services, and programmatic access to messaging data. We conclude the session by examining Exchange Server ActiveSync improvements.

TechNet Webcast : Exchange Server 2007 Client Access and Web Services (Level 200)

Learn about the Exchange 2007 implementation of the Autodiscover service. You can use this service to automatically configure Microsoft Office Outlook 2007 with connection settings so that it can easily connect to the Exchange 2007 server. The Support WebCast includes information about server and certificate configuration in various environments to achieve optimal functionality. Discover more yourself, and watch Support WebCast : Introduction to Autodiscover in Microsoft Exchange Server 2007.

Support WebCast : Introduction to Autodiscover in Microsoft Exchange Server 2007.

If you want to explore more, and get you on your way quickly, here are some webcasts that you might be interested in:

Happy Learning…

How to search for SMTP Servers in a domain programmatically using ADSI?

Here is a sample vbscript using which we can get SMTP servers instance names in a particular domain pragmatically via ADSI.

NOTE: Following programming examples is for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This sample code assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. This sample code is provided for the purpose of illustration only and is not intended to be used in a production environment.

Option Explicit
Dim conn
Dim com
Dim iAdRootDSE
Dim strNC
Dim strQry
Dim RS
Dim strstmsrv
Dim svsSmtpserver
Dim crServerName
 
set conn = createobject("ADODB.Connection")
set com = createobject("ADODB.Command")
Set iAdRootDSE = GetObject("LDAP://RootDSE")
 
strNC = iAdRootDSE.Get("configurationNamingContext")
 
conn.Provider = "ADsDSOObject"
conn.Open "ADs Provider"
com.ActiveConnection = Conn
com.ActiveConnection = Conn
 
Wscript.echo
Wscript.echo "SMTP Virtual Servers"
 
'Get SMTP server query using protocolCfgSMTPServer object class
strQry = "<LDAP://" & strNC & ">;(objectCategory=protocolCfgSMTPServer);name,distinguishedName;subtree"
 
com.ActiveConnection = conn
com.CommandText = strQry
 
Set RS = com.Execute
 
While Not RS.EOF
    strstmsrv = "LDAP://" & rs.fields("distinguishedName")
    set svsSmtpserver = getobject(strstmsrv)
    crServerName = mid(svsSmtpserver.distinguishedName,instr(svsSmtpserver.distinguishedName,"CN=Protocols,")+16,instr(svsSmtpserver.distinguishedName,",CN=Servers")-(instr(svsSmtpserver.distinguishedName,"CN=Protocols,")+16))
    wscript.echo
    wscript.echo "ServerName:" & crServerName
    
    RS.movenext
wend
 
Set RS=Nothing
Set com=Nothing
Set conn=Nothing

 

Here is another good example of where protocolCfgSMTPServer object class is used to find SMTP Virtual Server and set Message Restriction on an SMTP Virtual Server Using ADSI in VB @ Setting Message Restriction on an SMTP Virtual Server Using ADSI.

Hope this helps.

Download Available for Exchange Server 2007 Service Pack 2

You can now download Exchange Server 2007 Service Pack 2 from here Exchange Server 2007 SP2

We can refer to the following links to know more about SP2 in details:

Things which would be of interest for Exchange application developers are: 

  • Named Properties cmdlets - SP2 enables Exchange administrators to monitor their named property usage per database.
  • New User Interface for Managing Diagnostic Logging- SP2 enables Exchange administrators to easily configure and manage diagnostic logging from within the Exchange Management Console.

    Exchange Server 2007 Service Pack 2 (SP2), the Manage Diagnostic Logging Properties wizard is added to the Exchange Management Console. In Exchange Server 2007 Service Pack 1 or an earlier version, you must use the Exchange Management Shell to change diagnostic logging levels. for further reading Diagnostic Logging of Exchange Processes

  • Unable to open Outlook item attached using Attachments.Add and using the olByReference flag on the Outlook 2007

    One of our customer is sending Outlook item attached using Attachments.Add with olByReference Flag on Outlook 2007. If the recipient of the email tries to open the attached item

    will get “Microsoft Office Oulook could not complete the operation. One or more parameters values are not valid” exception.

    OlAttachErr

    To repro the issue we can use following sample VBA code snippet:

    NOTE: Following programming examples is for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This sample code assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. This sample code is provided for the purpose of illustration only and is not intended to be used in a production environment.

    Sub SendCurrentItemAsAttach()
        Set currItem = Application.ActiveInspector.CurrentItem
        currItem.Save
        Set RequestItem = Application.CreateItem(0)
        RequestItem.Subject = "Please check attached mail"
        RequestItem.HTMLBody = "Please check attached mail" & Chr(13) 
        RequestItem.To = "test@domain.com" 
        Set myAttachments = RequestItem.Attachments
        myAttachments.Add currItem, 4 'olByReference(4)
        RequestItem.Send
        Set RequestItem = Nothing
    End Sub

    The above issue is happening because of the design changes in the Outlook 2007.

    One workaround to address the above issue is to include a hyperlink in the email using the Outlook:\\<ENTRYID> protocol to link to the existing item rather than attaching the item ByRef. So to avoid above issue we can use following VBA sample code snippet:

    Sub SendCurrentItemAsAttach()
        Set currItem = Application.ActiveInspector.CurrentItem
        currItem.Save
        Set RequestItem = Application.CreateItem(0)
        RequestItem.Subject = "Please check attached mail"
        RequestItem.HTMLBody = "Please click to open the requestl" & Chr(13) & "<a href=Outlook:\\" & currItem.EntryID & ">Click Mail</a>"
        RequestItem.To = "test@domain.com"
        RequestItem.Send
        Set RequestItem = Nothing
    End Sub

    IMP: using Outlook:EntryID approach but it would works ONLY in case of HTML/RTF mail.

    References:

    FYI: Outlook 2003 and Exchange Server 2003 goes into Extended Support

    Outlook 2003 and Exchange Server 2003 goes into extended Support from 4/14/2009

    What is the difference between Mainstream Support, Extended Support, and online self-help support?

    Support provided

    Mainstream Support phase

    Extended Support phase

    Paid support (per-incident, per hour, and others)

    X

    X

    Security update support

    X

    X

    Non-security hotfix support

    X

    Requires extended hotfix agreement, purchased within 90 days of mainstream support ending.

    No-charge incident support

    X

       NA

    Warranty claims

    X

    NA

    Design changes and feature requests

    X

    NA

    Product-specific information that is available by using the online Microsoft Knowledge Base

    X

    X

    Product-specific information that is available by using the Support site at Microsoft Help and Support to find answers to technical questions

    X

    X

    IMP: Microsoft will NOT accept requests for warranty support, design changes, or new features during the Extended Support phase.

    To understand Support Lifecycle policy we can refer to Microsoft Support Lifecycle Policy FAQ

    To find the support timelines for other Microsoft products, visit the Select a Product for Lifecycle Information site (products listed by Product Family) or the Support Lifecycle Index site.

    Remove all PST from the Outlook Mailbox using VBScript

    If you would like to remove all of the Personal Folders file .PSTs attached to the Outlook Mailbox profile then we can use RemoveStore Method.

    Here is a sample VBScript to perform the job for us:

    NOTE: Following programming examples is for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This sample code assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. This sample code is provided for the purpose of illustration only and is not intended to be used in a production environment.

    'Sample script to remove Personal Folders files (.pst) from the current MAPI profile or session
    RemoveAllPST
     
    Sub RemoveAllPST()
    Dim objOL 'As New Outlook.Application
    Dim objFolders 'As Outlook.MAPIFolders
    Dim objFolder 'As Outlook.MAPIFolder
    Dim i 'As Interger
    Dim strPrompt 'As String
     
    Set objOL = CreateObject("Outlook.Application")
    Set objFolders = objOL.Session.Folders
    For i = objFolders.Count To 1 Step -1
    On Error Resume Next
        Set objFolder = objFolders.Item(i)
         
        'Prompt the user for confirmation
        If (InStr(1, objFolder.Name, "Mailbox") = 0) And (InStr(1, objFolder.Name, "Public Folders") = 0) Then
        
        strPrompt = ""
        strPrompt = "Are you sure you want to remove " & objFolder.Name
       
        If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then
            objOL.Session.RemoveStore objFolder
        End If
        End If
    Next
     
    End Sub

    We can also refer to the article mentioned below related to RemoveStore Method:

    NameSpace.RemoveStore Method
    http://msdn.microsoft.com/en-us/library/bb219923.aspx

    Hope this helps.

    Delegate Access and Delegate Access Management with Exchange Web Services.

    One of the common request from our customers is to provide interface to work programmatically with Delegate Settings for Outlook.

    Microsoft Exchange Server 2007 Service Pack 1 (SP1) introduces delegate access and delegate access management through Exchange Web Services. The following delegate access functionality is available starting with Exchange 2007 SP1:

    • Delegates can access the mailbox of a principal and perform search, create, delete, update, and copy operations.
    • You can enable delegate access to items based on folder-level permissions that are set by using the delegate management operations.
    • Delegates can create and send meeting messages on behalf of the principal.
    • Delegates can receive meeting messages that are forwarded by the principal and respond to them for the principal.
    • Users who have owner rights on a shared mailbox can open the mailbox and act as the owner.
    • Delegates can create notification subscriptions on folders in the mailbox of the principal.

    Here are the few links related to it:

    And if you would like to do it with ease then try out Exchange Web Services Managed API Beta

    And if you would like to do deep dive about how delegate access works with Outlook then explore it:

    So, there is lot to explore in the Messaging World… Feel free to drop me your question related to Microsoft Messaging APIs

    List delegates of the Outlook Mailbox using CDO 1.2.1 via VBScript

    I have recently worked out a VBScript to list delegate of the Outlook Mailbox using CDO 1.2.1 via VBScript and thought of share it with you all, here is the sample code:

    NOTE: Following programming examples is for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This sample code assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. This sample code is provided for the purpose of illustration only and is not intended to be used in a production environment.

     
    Dim objSession 
    Dim strProfileInfo 
    Dim strServer 
    Dim strMailbox 
    Dim objFolder
    Dim objMessages
    Dim objMessage
    Dim oFields
    Dim oField1
    Dim oField2
    Dim oFBFolder
     
    'TODO:Change Server and Mailbox info
    strServer="Server"
    strMailbox="User"
     
    strProfileInfo = strServer & vbLf & strMailbox
     
    Set objSession = CreateObject("MAPI.Session")
    objSession.Logon , , False, False, , True, strProfileInfo
     
    writelog( "Mailbox")
            
        writelog( "  ==> ")
        writelog( objSession.CurrentUser)
        writelog( vbCrLf)
    Msgbox "Logged On!!!"
     
    ' Reference the root folder by passing ID of ""
    Set oRoot = objSession.GetFolder("")
     
    'Connect to the Freebusy folder
    Set oFBFolder = oRoot.Folders.Item("Freebusy Data")
        Set objMessages = oFBFolder.Messages
     
        For Each objMessage In objMessages
     
            If objMessage.subject = "LocalFreebusy" Then
                'Get the message fields
     
                Set oFields = objMessage.Fields
                
                On Error Resume Next
     
        For i = 0 to UBound(oFields.Item(&H6844101E).Value(0))
      
                    Set oField1 = oFields.Item(&H6844101E)  ' PR_SCHDINFO_DELEGATE_NAMES
                           writelog "DELEGATE NAMES  ==> " & oField1.Value(0)(i)
                        writelog( vbCrLf)
     
                              Set oField2 = oFields.Item(&H686B1003) ' PR_DELEGATE_FLAGS
                  writelog "Delegate can see private  ==> " & oField2.Value(0)(i)
                              writelog( vbCrLf)
           Next
        End iF
    Next
     
    objSession.Logoff
     
    Set objSession =Nothing
     
    Set oField1 = Nothing
    Set oField2 = Nothing
    Set oFBFolder = Nothing
    Set oRoot = Nothing
     
    Msgbox "Done!!!"
     
    Sub WriteLog(ByVal strMessage)
        Dim fs
        Set fs = CreateObject("Scripting.FileSystemObject")
        Dim file
        Dim sScriptPath
        sScriptPath = Left(WScript.ScriptFullName, InstrRev(WScript.ScriptFullName, "\"))
        Set file = fs.opentextfile(sScriptPath & "DelegateListLog.txt", 8, True)
        file.Write strMessage
        file.Close
    End Sub

    Please refer to the following MAPI properties used in the above sample to list delegates of the mailbox:

    If you interested in exploring further details regarding how delegate settings works in Outlook then refer to:

    However, if you just targeting Exchange Server 2007, I would highly recommend you to use EWS(Exchange Web Services)

    Delegate Access and Delegate Access Management with Exchange Web Services

    Download for Office 2007 SP2 is available now

    Office 2007 SP2 is available for download

    The 2007 Microsoft Office Suite Service Pack 2 (SP2) provides customers with the latest updates to the 2007 Office suite (the products that are affected by this update are listed below). This download includes two types of fixes:

    • Previously unreleased fixes that were made specifically for this service pack.
      • In addition to general product fixes, this includes improvements in stability, performance, and security.
      • You can find out more information in Knowledge Base Article 953195, where product-specific changes are described.
    • All of the Public Updates, Security Updates, Cumulative Updates, and Hotfixes released through February 2009.

    Before installing this service pack, you are strongly encouraged to read 953195, which describes some big improvements introduced by SP2, and also calls out some important information that you should be aware of before installing.

    For the Outlook 2007 Specific changes in SP2 please refer to the Outlook 2007 improvements in the 2007 Office suite Service Pack 2 article.

    You can also download a workbook that contains a list of issues that are fixed by this service pack from the link mentioned below:

    Download the 2007 Office Service Pack 2 Changes.xlsx package

    Please let us know if you face any Outlook development related issues after upgrading to Office 2007 SP2.

    Posted by brijs | 1 Comments

    How to do FindFolder and MoveItem Operations of Exchange Web Services using VB.net

    In continuations of my previous post How to do FindItem and GetItem Operations of Exchange Web Services using VB.net ; Here is the Exchange Web Services sample in VB.net to perform following task:

    • FindFolder(How to perform FindFolder Operation to get FolderId of specific folder for the root of the mailbox)
    • MoveItem (How to perform MoveItem Operation to move an item to the another folder within the mailbox)

    NOTE: Following programming examples is for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This sample code assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. This sample code is provided for the purpose of illustration only and is not intended to be used in a production environment. 

    Private Sub cmdMove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdMove.Click
            Try
                If lstMails.SelectedItems.Count = 1 Then
                    Dim itemID As New ItemIdType
                    itemID.Id = lstMails.SelectedItems(0).SubItems(3).Text
     
                    'Find the folderId to which we want to move item
                    Dim parentFolder As New DistinguishedFolderIdType
                    parentFolder.Id = DistinguishedFolderIdNameType.root
                    Dim tfTargetFolder As New FolderIdType
                    'Change the name of the folder we are searching for FolderID
                    tfTargetFolder = FindFolder(ServiceBinding, parentFolder, "Test")
     
                    Dim newItemID As New ItemIdType
                    'Move am Item based on ItemId and FolderID
                    newItemID = MoveItemtoTest(ServiceBinding, itemID.Id, tfTargetFolder)
                    Dim strId As String
                    strId = "New ItemID " + newItemID.Id.ToString
                    MessageBox.Show(strId, "Item Moved", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Else
                    MessageBox.Show("Please select a item in list to move", "Item to Move", MessageBoxButtons.OK, MessageBoxIcon.Information)
                End If
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End Sub
     
    Public Shared Function FindFolder(ByVal serviceBinding As ExchangeServiceBinding, ByVal fiFolderID As DistinguishedFolderIdType, ByVal fnFldName As String) As FolderIdType
     
            Dim rvFolderID As New FolderIdType
            ' Create the request and specify the travesal type
            Dim findFolderRequest As FindFolderType = New FindFolderType()
            findFolderRequest.Traversal = FolderQueryTraversalType.Deep
     
            ' Define the properties returned in the response
            Dim responseShape As FolderResponseShapeType = New FolderResponseShapeType()
            responseShape.BaseShape = DefaultShapeNamesType.Default
            findFolderRequest.FolderShape = responseShape
     
            ' Identify which folders to search
            Dim folderIDArray() As DistinguishedFolderIdType = New DistinguishedFolderIdType(1) {}
            folderIDArray(0) = New DistinguishedFolderIdType()
            folderIDArray(0).Id = fiFolderID.Id
     
            'Add Restriction for DisplayName
            Dim ffRestriction As New RestrictionType
            Dim ieToType As New IsEqualToType
            Dim diDisplayName As New PathToUnindexedFieldType
            diDisplayName.FieldURI = UnindexedFieldURIType.folderDisplayName
     
            Dim ciConstantType As New FieldURIOrConstantType
            Dim cvConstantValueType As New ConstantValueType
            cvConstantValueType.Value = fnFldName
            ciConstantType.Item = cvConstantValueType
            ieToType.Item = diDisplayName
            ieToType.FieldURIOrConstant = ciConstantType
            ffRestriction.Item = ieToType
            findFolderRequest.Restriction = ffRestriction
     
            ' Add the folders to search to the request
            findFolderRequest.ParentFolderIds = folderIDArray
     
            Try
                ' Send the request and get the response
                Dim findFolderResponse As FindFolderResponseType = serviceBinding.FindFolder(findFolderRequest)
                ' Get the response messages
                If findFolderResponse.ResponseMessages.Items(0).ResponseClass = ResponseClassType.Error Then
                    MessageBox.Show("Error Occured")
                    MessageBox.Show(findFolderResponse.ResponseMessages.Items(0).MessageText)
                    Return Nothing
                Else
                    Dim rmta() As ResponseMessageType = findFolderResponse.ResponseMessages.Items
                    Dim rmt As ResponseMessageType
                    For Each rmt In rmta
                        ' Cast to the correct response message type
                        Dim ffResponse As FindFolderResponseMessageType = rmt
                        Dim fFoundFolder As FolderType
                        For Each fFoundFolder In ffResponse.RootFolder.Folders
                            rvFolderID = fFoundFolder.FolderId
                            'MessageBox.Show(fFoundFolder.DisplayName)
                        Next
                    Next
                    'Return the FolderID of the last folder found
                    Return (rvFolderID)
                End If
            Catch e As Exception
                MessageBox.Show(e.Message)
                Return Nothing
            End Try
        End Function
    Public Shared Function MoveItemtoTest(ByVal serviceBinding As ExchangeServiceBinding, ByVal itemID As String, ByVal trgfldID As FolderIdType) As ItemIdType
     
            'Setup FolderId and ItemId to be passed to MoveItem
            Dim tfTargetFolder As TargetFolderIdType = New TargetFolderIdType()
            tfTargetFolder.Item = trgfldID
     
            Dim iiItemId As ItemIdType = New ItemIdType()
            iiItemId.Id = itemID
     
            'Create request to move Item and specify properties
            Dim miMoveItemRequest As MoveItemType = New MoveItemType()
            miMoveItemRequest.ItemIds = New ItemIdType(1) {}
            miMoveItemRequest.ItemIds(0) = iiItemId
            miMoveItemRequest.ToFolderId = tfTargetFolder
     
            Dim nID As New ItemIdType
            Try
                ' Send the request and get the response
                Dim miResponse As MoveItemResponseType = serviceBinding.MoveItem(miMoveItemRequest)
                If miResponse.ResponseMessages.Items(0).ResponseClass = ResponseClassType.Error Then
                    MessageBox.Show("Error Occured")
                    MessageBox.Show(miResponse.ResponseMessages.Items(0).MessageText)
                    Return Nothing
                Else
                    Dim iirmt As ItemInfoResponseMessageType = miResponse.ResponseMessages.Items(0)
                    If iirmt.Items.Items.Length > 0 Then
                        'Get updated ItemId from the Response Message
                        nID = iirmt.Items.Items(0).ItemId
                        MessageBox.Show("Item Moved")
                        'Return updated ItemID
                        Return nID
                    Else
                        Return Nothing
                    End If
                End If
            Catch e As Exception
                MessageBox.Show(e.Message)
                Return Nothing
            End Try
        End Function

    We can refer to the following articles related to the EWS:

    While we can workout more with Exchange Web Service auto generated proxies but don’t forget to have look at Microsoft Exchange Web Services (EWS) Managed API 1.0 to do stuff with less sweat. :)

    How to send Excel contents as PDF attachment with the email using CDOSYS

    One of my customer would like to send Excel 2007 worksheet contents as email using CDOSYS. We are facing issues regarding formatting of the contents in the resultant emails on the different email clients. Then we decided to send contents as PDF attachment to avoid such issues.

    Here is the sample code VBA snippet used:

    NOTE: Following programming examples is for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This sample code assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. This sample code is provided for the purpose of illustration only and is not intended to be used in a production environment.

    Sub SendMail()
    Dim filepath As String
    filepath = "\\server\test\Excel 2007 Chart.pdf" 'TODO:change filepath for the temp pdf file
     'Exporting range of the excel contents which need to sent out
        Range("A1:I22").Select
        Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
            filepath, _
            Quality:=xlQualityStandard, IncludeDocProperties:=False, IgnorePrintAreas _
            :=False, OpenAfterPublish:=False
     'Setting up CDOSYS configuration to send out the email 
    Set iMsg = CreateObject("CDO.Message")
        Set iConf = CreateObject("CDO.Configuration")
        Set Flds = iConf.Fields
        With Flds
            .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'send via port
            .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "ServerName" 'TODO:update the SMTP server name here
            .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
            .Update
        End With
     
        With iMsg
            Set .Configuration = iConf
            .From = "xyz@domain.com" 'TODO:change email address here
            .To = "abc@domain.com" 'TODO:change email address here
            
            .Subject = "Test message with PDF Attachment"
            .HTMLBody = "Please find the attache excel pdf contents report"
            .AddAttachment (filepath)
            .Send
        End With
     
        Set iMsg = Nothing
        Set iConf = Nothing
    End Sub
     

    Hope this helps.

     

    Please feel free to write me if you have question related to Microsoft Messaging APIs.

    Posted by brijs | 2 Comments
    More Posts Next page »
     
    Page view tracker