This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

API for Outlook

Does anyone have a sample where when a user sends an email from outlook a question is asked "Do you want to save to M-files? Yes or No"

If the user clicks yes the save/properties window is displayed

;D
Parents
  • Others have proposed nice solutions how to make sent messages appear in M-Files, and they might be better suited here.

    However because the topic is M-Files API, I'll attach quick & dirty example how to push an e-mail to M-Files using the client API and VBA. Just because creating an object with metadata card is not completely trivial task. This is not a complete solution, nor the only way to do the job.

    In order to run the code, you need to place it in to "ThisOutlookSession" page in Outlook's Visual Basic Editor. I gave a try with Outlook 2003, but it should work at least with Outlook 2007, too. As well, you need to add a reference to M-Files API module (VB Editor, Tools -> References...) and to deal with Outlook's macro security settings so that macros can be run. The code triggers when an e-mail is about to be sent.

    Cheers,
    - Ari


    Option Explicit

    ' Triggered when an e-mail is sent.
    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

    ' Error handling.
    On Error GoTo ErrorHandling

    ' Test and get an interface to the email item.
    If Not TypeOf Item Is Outlook.MailItem Then
    Exit Sub
    End If
    Dim emailItem As Outlook.MailItem
    Set emailItem = Item

    ' Prompt for save.
    If MsgBox("Save the message to M-Files?", vbYesNo Or vbMsgBoxSetForeground) = vbNo Then
    Exit Sub
    End If

    ' Get the M-Files client application interface and the vault connection.
    ' Note: fixed vault name.
    Dim clientApp As New MFilesAPI.MFilesClientApplication
    Dim vaultConnection As MFilesAPI.vaultConnection
    Set vaultConnection = clientApp.GetVaultConnection("Sample")

    ' Bind and log in to the vault.
    Dim vault As MFilesAPI.vault
    Set vault = vaultConnection.BindToVault(0, True, True)
    If vault Is Nothing Then GoTo Cancelled

    ' Create file classes for supported file formats.
    Dim objectFileClasses As New MFilesAPI.FileClasses
    objectFileClasses.Add -1, New MFilesAPI.FileClass
    objectFileClasses(1).LoadByExtension "msg"

    ' Build ObjectCreationInfo for the metadata card with file class selector.
    ' In order to keep this simple, pretty much all editing is denied.
    Dim objCreationInfo As New MFilesAPI.objectCreationInfo
    objCreationInfo.SetTitleAsDatatypeText emailItem.Subject, True
    objCreationInfo.SetObjectType MFilesAPI.MFBuiltInObjectTypeDocument, False
    objCreationInfo.SetSingleFileDocument True, False
    objCreationInfo.SetSelectableFileClasses objectFileClasses
    objCreationInfo.SetSelectedFileClass objectFileClasses(1), False
    objCreationInfo.SetExtension "msg", False

    ' Disable object creation because we will create it by ourselves later.
    objCreationInfo.SetDisableObjectCreation True

    ' Display the metadata card for new object
    Dim objWindowResult As MFilesAPI.objectWindowResult
    Set objWindowResult = vault.ObjectOperations.ShowNewObjectWindow( _
    0, MFObjectWindowModeInsertSaveAsType, objCreationInfo)
    If objWindowResult.result = MFObjectWindowResultCodeCancel Then GoTo Cancelled

    ' Create new single-file document with empty file.
    ' Use properties provided by the metadata card to fill the object's metadata.
    Dim objVersionAndProperties As MFilesAPI.objectVersionAndProperties
    Set objVersionAndProperties = vault.ObjectOperations.CreateNewEmptySingleFileDocument( _
    objWindowResult.Properties, _
    objWindowResult.Properties.SearchForProperty(MFBuiltInPropertyDefNameOrTitle).GetValueAsUnlocalizedText, _
    objWindowResult.SelectedFileClass.Extension)

    ' Resolve the path to the newly-created empty document file.
    Dim path As String
    Let path = vault.ObjectFileOperations.GetPathInDefaultView( _
    objVersionAndProperties.ObjVer.ObjID, _
    objVersionAndProperties.ObjVer.Version, _
    objVersionAndProperties.VersionData.Files(1).FileVer.ID, _
    objVersionAndProperties.VersionData.Files(1).FileVer.Version)

    ' Save the e-mail over the empty file.
    emailItem.SaveAs path

    ' Check in right away, unless we are in offline mode.
    If vault.ClientOperations.IsOnline Then
    vault.ObjectOperations.CheckIn objVersionAndProperties.ObjVer
    End If

    Exit Sub

    ' Error handling.
    ErrorHandling:
    MsgBox Err.Description
    Exit Sub

    ' Cancellation.
    Cancelled:
    Cancel = True
    emailItem.Display
    Exit Sub

    End Sub
Reply
  • Others have proposed nice solutions how to make sent messages appear in M-Files, and they might be better suited here.

    However because the topic is M-Files API, I'll attach quick & dirty example how to push an e-mail to M-Files using the client API and VBA. Just because creating an object with metadata card is not completely trivial task. This is not a complete solution, nor the only way to do the job.

    In order to run the code, you need to place it in to "ThisOutlookSession" page in Outlook's Visual Basic Editor. I gave a try with Outlook 2003, but it should work at least with Outlook 2007, too. As well, you need to add a reference to M-Files API module (VB Editor, Tools -> References...) and to deal with Outlook's macro security settings so that macros can be run. The code triggers when an e-mail is about to be sent.

    Cheers,
    - Ari


    Option Explicit

    ' Triggered when an e-mail is sent.
    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

    ' Error handling.
    On Error GoTo ErrorHandling

    ' Test and get an interface to the email item.
    If Not TypeOf Item Is Outlook.MailItem Then
    Exit Sub
    End If
    Dim emailItem As Outlook.MailItem
    Set emailItem = Item

    ' Prompt for save.
    If MsgBox("Save the message to M-Files?", vbYesNo Or vbMsgBoxSetForeground) = vbNo Then
    Exit Sub
    End If

    ' Get the M-Files client application interface and the vault connection.
    ' Note: fixed vault name.
    Dim clientApp As New MFilesAPI.MFilesClientApplication
    Dim vaultConnection As MFilesAPI.vaultConnection
    Set vaultConnection = clientApp.GetVaultConnection("Sample")

    ' Bind and log in to the vault.
    Dim vault As MFilesAPI.vault
    Set vault = vaultConnection.BindToVault(0, True, True)
    If vault Is Nothing Then GoTo Cancelled

    ' Create file classes for supported file formats.
    Dim objectFileClasses As New MFilesAPI.FileClasses
    objectFileClasses.Add -1, New MFilesAPI.FileClass
    objectFileClasses(1).LoadByExtension "msg"

    ' Build ObjectCreationInfo for the metadata card with file class selector.
    ' In order to keep this simple, pretty much all editing is denied.
    Dim objCreationInfo As New MFilesAPI.objectCreationInfo
    objCreationInfo.SetTitleAsDatatypeText emailItem.Subject, True
    objCreationInfo.SetObjectType MFilesAPI.MFBuiltInObjectTypeDocument, False
    objCreationInfo.SetSingleFileDocument True, False
    objCreationInfo.SetSelectableFileClasses objectFileClasses
    objCreationInfo.SetSelectedFileClass objectFileClasses(1), False
    objCreationInfo.SetExtension "msg", False

    ' Disable object creation because we will create it by ourselves later.
    objCreationInfo.SetDisableObjectCreation True

    ' Display the metadata card for new object
    Dim objWindowResult As MFilesAPI.objectWindowResult
    Set objWindowResult = vault.ObjectOperations.ShowNewObjectWindow( _
    0, MFObjectWindowModeInsertSaveAsType, objCreationInfo)
    If objWindowResult.result = MFObjectWindowResultCodeCancel Then GoTo Cancelled

    ' Create new single-file document with empty file.
    ' Use properties provided by the metadata card to fill the object's metadata.
    Dim objVersionAndProperties As MFilesAPI.objectVersionAndProperties
    Set objVersionAndProperties = vault.ObjectOperations.CreateNewEmptySingleFileDocument( _
    objWindowResult.Properties, _
    objWindowResult.Properties.SearchForProperty(MFBuiltInPropertyDefNameOrTitle).GetValueAsUnlocalizedText, _
    objWindowResult.SelectedFileClass.Extension)

    ' Resolve the path to the newly-created empty document file.
    Dim path As String
    Let path = vault.ObjectFileOperations.GetPathInDefaultView( _
    objVersionAndProperties.ObjVer.ObjID, _
    objVersionAndProperties.ObjVer.Version, _
    objVersionAndProperties.VersionData.Files(1).FileVer.ID, _
    objVersionAndProperties.VersionData.Files(1).FileVer.Version)

    ' Save the e-mail over the empty file.
    emailItem.SaveAs path

    ' Check in right away, unless we are in offline mode.
    If vault.ClientOperations.IsOnline Then
    vault.ObjectOperations.CheckIn objVersionAndProperties.ObjVer
    End If

    Exit Sub

    ' Error handling.
    ErrorHandling:
    MsgBox Err.Description
    Exit Sub

    ' Cancellation.
    Cancelled:
    Cancel = True
    emailItem.Display
    Exit Sub

    End Sub
Children
No Data