Azure Logic Apps: How to send an email with an attachment

Synopsis

This post is a short, simple 20 minute recipe on how to automate the sending of emails, attaching any files that have been uploaded to a storage account container.

Components:

  1. Azure Storage Account
  2. Azure Logics Apps
1. Azure Storage Account

Provsision or select an existing Azure Storage Account in which will we provision a container for the storage of the uploaded files, which will be added as the email attachments.

Feel free to click here for a fast and easy storage account deployment using powershell.

Azure Storage Account > Containers > Add Container.

Upload a simple text1.txt file into the container.

Make sure key access is enabled to allow the Logic Apps to connect.

2. Azure Logics Apps

Provision a Logic Apps > Add >

Basic tab > provide a globally unique name and publish as a workflow and place in your region.

Determine your Plan type – if you select the Enterprise grade Standard plan – then you have the option of selecting the Windows and pricing plan, as well as the Zone redundancy > Create.

(I am selecting the more basic Consumption plan for this sandbox)

Logic Apps Designer:

Blank Logic App > Add my trigger > search for “blob” > select Azure blob storage >

Select When a blob is added or modified v2 >

Connection name > add the storage account name for simplicity,

Authentication type > access key (will be grabbed from the storage account primary key),

Storage account name > add the storage account name,

Storage Account Access Key > go to the storage account, Access Keys > copy and paste the primary key > Create

(storage account > Access keys)

Parameters tab:

Storage account name > use connection settings (created earlier)

Container > (click on the folder and find the container you designated earlier)

Number of blobs to return > you define the maximum number of files to retrieve per polling interval (based on the delta’s created / rate of change per polling interval). Ive left the 10 default. You can set the max to 100.

How often do you want to check for items? > based on your update frequency required and take into consideration that each trigger is cost incurring per plan. Costs can be found here.

(Im setting my interval for every 1 minute for demo purposes)

Next

Choose an operation > blob content

Actions > Get blob content (v2)

Parameters tab:

Storage Account Name > insert the Use connection settings

Blob > click on edit bar > select List of Files Path

Infer content type > Yes

Next Step

Add an action >

Choose an operation > outlook

select > outlook.com

search for > send email

select > send an email (v2)

Sign in with your user account or as a service account. To learn how to do this easily, click here.

(Im in my sandbox, so Im going to use my own user account).

Parameters tab:

To > add the recipients email address

Subject > add dynamic content > List of Files Names

Body > add at your discretion

Importance > add at your discretion

Add new parameter > select Attachments

Attachments Name 1 > List of Files Names

Attachments Contents > Files Content

Save

Testing / Verification Process

  1. You previously uploaded a blob file into the container and can now either wait for the configured time out value, or
  2. Upload a file and manually trigger the Logic App via Run Trigger.
  3. If your logic app is configured correctly, you will notice emails arrive on the predefined intervals.

(If you remember, I had configured my time interval to be every 1 minute?)

These are the 3 files I uploaded for end user verification.

These are the same 3 files having arrived in my Outlook being subject to the 1 minute schedule.

Connect using other accounts

If you try connecting to Outlook by using a different account than the one currently signed in to Azure, you might get single sign-on (SSO) errors. This problem happens when you sign in to the Azure portal with one account, but use a different account to create the connection. The designer expects that you use the account that’s signed in to the Azure portal. To resolve this problem, you have these options:

  • Set up the other account with the Contributor role in your logic app’s resource group.
    1. On your logic app’s resource group menu, select Access control (IAM). Set up the other account with the Contributor role.For more information, see Assign Azure roles using the Azure portal.
    2. After you set up this role, sign in to the Azure portal with the account that now has Contributor permissions. You can now use this account to create the connection to Outlook.
  • Set up the other account so that your work or school account has “send as” permissions.If you have admin permissions, on the service account’s mailbox, set up your work or school account with either Send as or Send on behalf of permissions. For more information, see Give mailbox permissions to another user – Admin Help. You can then create the connection by using your work or school account. Now, in triggers or actions where you can specify the sender, you can use the service account’s email address.For example, the Send an email action has an optional parameter, From (Send as), which you can add to the action and use your service account’s email address as the sender. To add this parameter, follow these steps:
    1. In the Send an email action, open the Add a parameter list, and select the From (Send as) parameter.
    2. After the parameter appears on the action, enter the service account’s email address.

4 comments

  1. Howdy! I’m at work browsing your blog fгom my new iphone
    4! Just wanted to say I love reading thr᧐ᥙgh уour blog and look forward to all your
    posts! Carry on tһе great work!

Leave a comment

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