Logic Apps: How to Save File from Email onto SharePoint – A Step-by-Step Guide
Image by Mattaeus - hkhazo.biz.id

Logic Apps: How to Save File from Email onto SharePoint – A Step-by-Step Guide

Posted on

Are you tired of manually saving files from emails to SharePoint? Do you want to automate this process and free up more time for important tasks? Look no further! In this article, we’ll show you how to use Logic Apps to save files from emails directly to SharePoint. It’s easier than you think, and we’ll guide you through every step of the way.

What You’ll Need

To get started, you’ll need the following:

  • A Microsoft Azure account (if you don’t have one, sign up for a free trial)
  • A SharePoint site with the necessary permissions
  • An email account (Office 365 or any other email provider)
  • Logic Apps (you can create a new logic app or use an existing one)

Step 1: Create a New Logic App

Log in to your Azure account and navigate to the Logic Apps dashboard. Click on “Create a logic app” and give your app a name (e.g., “Save Email File to SharePoint”). Choose a subscription, resource group, and location, and then click “Create.”


{
  "name": "Save Email File to SharePoint",
  "type": "Microsoft.Logic/workflows",
  ...
}

Step 2: Add a Trigger

In the Logic Apps designer, click on “Add a trigger” and search for “Office 365 Outlook.” Select the “When a new email arrives” trigger and sign in to your email account to authenticate.

Configure the trigger to fetch emails from a specific inbox or folder. You can also set up filters to only trigger the workflow when an email contains a specific subject or attachment.


{
  "type": "Request",
  "kind": "Http",
  "inputs": {
    "method": "GET",
    "uri": "https://graph.microsoft.com/v1.0/me/mailFolders/{folderId}/messages",
    "headers": {
      "Authorization": "Bearer @{BODY['token']}"
    }
  }
}

Step 3: Add an Action

Click on “Add an action” and search for “SharePoint.” Select the “Create file” action and sign in to your SharePoint account to authenticate.

Configure the action to create a new file in a specific SharePoint library or folder. You can also specify the file name, content type, and other metadata.


{
  "type": "ApiConnection",
  "api": {
    "id": "/subscriptions/{subscriptionId}/providers/Microsoft.Web/locations/{location}/apiManagementAccounts/{apiManagementAccount}/api"
  },
  "inputs": {
    "body": "@{body('Get_email')?.Body}",
    "headers": {
      "Content-Type": "application/octet-stream"
    },
    "uri": "https://{siteUrl}/_api/web/AddUrl(webUrl=/sites/{siteName}/Shared Documents,url=@{body('Get_email')?.Attachments[0]?.Name})"
  }
}

Step 4: Add a Condition

Click on “Add a condition” to check if the email has an attachment. You can use the “Has attachment” condition to check if the email contains at least one attachment.


{
  "type": "Condition",
  "expression": {
    "and": [
      {
        "equals": [
          "@{body('Get_email')?.Attachments.Length}",
          1
        ]
      }
    ]
  }
}

Step 5: Add a For Each Loop

If the email has multiple attachments, you’ll need to use a “For each” loop to iterate through each attachment and save it to SharePoint. Click on “Add a for each” and select the “Attachments” array.


{
  "type": "Foreach",
  "foreach": "@body('Get_email')?.Attachments",
  "actions": {
    "Create_file": {
      "type": "ApiConnection",
      "api": {
        "id": "/subscriptions/{subscriptionId}/providers/Microsoft.Web/locations/{location}/apiManagementAccounts/{apiManagementAccount}/api"
      },
      "inputs": {
        "body": "@item()",
        "headers": {
          "Content-Type": "application/octet-stream"
        },
        "uri": "https://{siteUrl}/_api/web/AddUrl(webUrl=/sites/{siteName}/Shared Documents,url=@item().Name)"
      }
    }
  }
}

Step 6: Save and Test Your Logic App

Click “Save” to save your Logic App. You can then test your app by sending an email with an attachment to the specified inbox or folder.

Monitor the Logic Apps dashboard to see if the workflow is triggered successfully and the file is saved to SharePoint. If you encounter any errors, check the error messages and debug your app accordingly.

Best Practices and Troubleshooting Tips

To ensure your Logic App runs smoothly, follow these best practices and troubleshooting tips:

  • Use specific folders and inboxes to trigger the workflow, rather than checking the entire inbox.
  • Use filters to only trigger the workflow when an email contains a specific subject or attachment.
  • Test your app with different email scenarios and attachment types.
  • Monitor your app’s performance and adjust the trigger frequency or concurrency settings as needed.
  • Check the SharePoint file size limits and adjust your app accordingly.
Error Message Solution
“Authentication failed” Check your email and SharePoint credentials, and ensure you have the necessary permissions.
“File already exists” Check your SharePoint file naming conventions and adjust your app to append a unique identifier to the file name.
“Attachment is too large” Check your SharePoint file size limits and adjust your app to split large attachments into smaller chunks.

Conclusion

And that’s it! With these simple steps, you’ve automated the process of saving files from emails to SharePoint using Logic Apps. You’ve also learned some best practices and troubleshooting tips to ensure your app runs smoothly.

Logic Apps is a powerful tool that can help you automate countless workflows and tasks. By following this tutorial, you’ve taken the first step in harnessing the power of Logic Apps to streamline your business processes.

So, what are you waiting for? Start creating your own Logic Apps today and see the benefits for yourself!

Happy automating!

Frequently Asked Question

Get the scoop on saving files from emails onto SharePoint using Logic Apps!

Q1: What’s the best way to connect my email account to Logic Apps?

To connect your email account to Logic Apps, you’ll need to create a new connection using the Office 365 Outlook connector. This will allow you to authenticate and authorize Logic Apps to access your email account. Just follow the prompts to sign in and grant the necessary permissions!

Q2: How do I trigger my Logic App to run when I receive a new email with an attachment?

Easy peasy! You’ll want to set up a new trigger using the “When a new email arrives” option. From there, configure the trigger to only fire when an email has an attachment. You can do this by adding a condition to check if the “Has Attachment” property is true. VoilĂ !

Q3: What’s the best way to extract the attachment from the email and save it to SharePoint?

Logic Apps has a built-in action for extracting attachments from emails, aptly named “Get attachment.” Use this action to retrieve the attachment, and then add a new action to create a file in SharePoint. You can specify the file location, filename, and even add metadata like the email subject or sender!

Q4: Can I customize the filename of the attachment before saving it to SharePoint?

You bet! You can use the “Set variable” action to create a custom filename based on the email subject, sender, or even a timestamp. Then, use this variable as the filename when creating the file in SharePoint. Get creative and make it your own!

Q5: How do I test my Logic App to ensure it’s saving files correctly?

Before going live, make sure to test your Logic App with a sample email containing an attachment. Use the “Run” button to execute the logic app and verify that the file is saved correctly in SharePoint. You can also use the “Debug” feature to step through the flow and identify any issues. Happy testing!

Leave a Reply

Your email address will not be published. Required fields are marked *