The M-Files Community will be updated on Tuesday, April 2, 2024 at 10:00 AM EST / 2:00 PM GMT and the update is expected to last for several hours. The site will be unavailable during this time.

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
  • Former Member
    Former Member
    I'm not that familiar with Outlook API, but you can sure do it if it allows you to add a handler here and there.

    Anyway, as an alternative, how about configuring M-Files Server to read another mail box, and whenever you need to save the important email to M-Files, you will just add that mail address in the cc or bcc field. M-Files offers the ability to save important e-mail in a controlled manner. The messages can be transferred directly from the mail server to the document vault without the need for separate actions by the user, using the "Connections to External Sources / Mail Sources" functionality.

    Here's something from the User's Guide:

    The organization also may want to save important sent e-mail to M-Files. Such important messages could be, e.g., proposals and confirmation of orders. The organization can create a new archive e-mail account to which M-Files is connected. From this box M-Files imports all e-mail to the document vault and then deletes the messages from the mail server. Important sent messages can be archived in M-Files by sending the message to the archive box by means of the Cc or Bcc fields. To avoid junk mail, it is possible to set the e-mail account to accept mail from internal users only.


    Could this be a solution?

    Best regards,
    Samppa
  • Thanks Samppa

    In theory that would work, but we will have to rely on users including the m-files email address, which i know after a few weeks they will not.

    If the system asked them to save it to m-files they are more likely to do it.

    I think it can be done with an office macro but need to do some research

    Thanks for your help
    :)
  • Former Member
    Former Member

    I think it can be done with an office macro but need to do some research


    Macro could be one solution, as you stated.

    Also, if you want to adapt the "common mail box" solution, at least in Outlook 2007 you can set actions for outgoing emails too. Maybe you can run a some sort of custom action there, and pop up the meta data card of M-Files. Or ask if this should be sent to M-Files' box (in cc).

    Edit: I had a quick look on Outlook 2007 and its VBA interface. It seems to me that making such feature (save in M-Files when sending) would not be that hard.

    Best regards,
    Samppa
  • bwill1980, if you use MS Exchange Server in your organization you already have another way to save messages to M-Files. MS Exchange features message journaling.

    Take a look at the Microsoft webpage for MS Exchange Journaling and evaluate if it suits your needs.
  • Former Member
    Former Member

    Take a look at the Microsoft webpage for MS Exchange Journaling and evaluate if it suits your needs.


    I agree that this is a solution to overcome the cc/bcc problem, but if I understood correctly, the emails are still saved in "bulk" manner. Of course there's an option that M-Files Server can apply fixed property values for all emails, or read those from headers, but it still won't be able to make the relationship between the email and recipient object (e.g. customer object in M-Files). If you add an M-Files API component there that is able to do the linking (based on the information in CRM & M-Files), that would be nice. Or, as bwill1980 suggested, let the user decide and fill in the required meta data.

    Even though using the journaling option it is possible to fill the requirements of some regulatory aspects, it might not the best solution, atleast for small businesses. And also if only a small portion of emails are to be saved, it is a waste of resources to save everything.

    Best regards,
    Samppa
  • Former Member
    Former Member
    Hi Guys,

    Glad to see others thinking about this question.

    I guess the other thing to consider is a way to prevent responses to emails, say related to a project, from becoming separate documents. Perhaps the response should be treated as a new version of the previously saved email. I guess you'd have to check the email out to prevent other recipients from attempting to respond at the same time. Its a little awkward to do at the moment. These are the steps I need to execute currently to maintain the properties on the email.

    Step 1. Save the initial email to the M-Files project. If selected from sent folder it records proof the email was sent.

    Step 2. On receiving a reply, the original email needs to be checked out and the new one replacing the original entered with the "replace with" option.

    I'm thinking another way to handle this may be to add some rule filtering to the email import connector.
    Rules like;
    - if email address contains @company1.com then relate the email to the company object that has company1.com as the email domain... Something similar may apply for contacts
    - if email has something in the header (say [Project: ID] then relate back to project...
    These could be handy for other things also.

    Another possibility may be concept of an email conversation object / document. Emails which are identified as being an extension of the same conversation would automatically update the previous version with M-Files.

    Its a complicated space however I think its worth sorting out.

    Cheers
    Rob.

  • 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
  • Former Member
    Former Member

    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.


    Nice work Ari, thanks! I can confirm that it works with Outlook 2007 nicely.

    Best regards,
    Samppa
  • Cheers Ari

    Thats just what I'm looking for. Although it would be best to somehow save the email after its been sent.

    Thanks for you help again

    ;D
  • Former Member
    Former Member
    I have been looking for the same functionality as well in outlook.

    Another area is when sending an item from M-Files via email I would like to see the email captured there as well. The email should us the Windows Commands email as this gives the signature as the one directly for M-Files does not