This repository contains source files for a containerized Azure Function for converting EML files into PDF 📧. There is also a 💪 Bicep file for easy deployment. Built container available with docker pull ghcr.io/miberr/azure-function-convert-email-to-pdf:latest.
- 🤓 Function source code for creating your own containers
- 💪 Bicep file for deploying the resources right away
- 🤖 Ready made Azure Logic App to convert incoming emails
- 📦 Built container available with
docker pull ghcr.io/miberr/azure-function-convert-email-to-pdf:latest
Note
- Azure subscription
- Resource group in Azure
- Azure CLI installed on your machine
- Basic understanding of containerized applications
-
Download the 💪 Bicep file to your machine
-
Open terminal
-
Login to Azure CLI with command
az login. A popup opens, login with your credentials. -
If you have multiple subscriptions, select the one you want to deploy to by typing its number and pressing enter
-
Run command
az deployment group create --template-file .\infrastructure.bicep --resource-group rg-emailtopdftest-dev --parameters environment=dev appName=emailtopdfwith the following parameters:- .\infrastructure.bicep is the path to the downloaded template file
- rg-emailtopdftest-dev the resource group name
- dev is the environment, either dev or prod accepted
- emailtopdf is the app name, this needs to be unique
In case there is a conflict with a name for example, the CLI will tell you about it. If you see no red, that means the deployment was successful 🥳.
-
Navigate to your resource group in Azure Portal. It should now look like this:
-
To initialize the secrets in Key Vault we have to send a POST request to the new endpoint.
-
Find the url by navigating to the Container App
-
Copy the value
-
Add the uri at the end
/api/convertEmlToPdf -
Send a request with your chosen tool. Make sure you include the x-functions-key header. The value can be what ever, for example
test. You should get 401 Unauthorized response back.POST https://xxxx.westeurope.azurecontainerapps.io/api/convertEmlToPdf x-functions-key: test { "file": "UmVjZWl2ZWQ6IGZyb20gVkkwUDE5MU1..." }
-
-
The last configuration to do is to open the API connections for Outlook and OneDrive to authorize them. Click on the first one.
-
Click on the error, then Authorize, login with your account and finally select Save
-
Repeat for the another connection.
-
Now send an email to the inbox you connected to and wait for the file to appear in OneDrive 😎
Warning
You should use what ever account you want to connect to an email to and what users OneDrive. It's best practice to use service accounts for these kind of scenarios.
As you now have everything installed, you can just sit back and relax 🏖️. If you require modifications to the Logic App for example, you cannot use the 💪 Bicep file anymore cause it would overwrite the workflow.
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
This project was created as part of a blog post on converting emails into PDFs. You can read the full post here.