CloudMailin allows you to receive emails via an HTTP POST, essentially sending email to a webhook.

As we discussed in our post about [email attachments on AWS](/blog/what_are_S3_attachments/),
the default maximum size for web servers can often be a little low. In fact, the default in
the .net Framework is 4MB. This would mean that when receiving email via HTTP POST in the
.net Framework the maximum email size we could receive is 4MB, including email attachments.
Whilst we could modify our config and set the
[maxRequestLength parameter](https://docs.microsoft.com/en-us/dotnet/api/system.web.configuration.httpruntimesection.maxrequestlength)
CloudMailin gives a better option.

When receiving email on Azure we want to make sure that your servers don't have to worry about
attachments. That's why CloudMailin can parse the attachements from email and send the email
attachment to Azure Blob Storage automatically. When we do this we allow the web application
to receive a small HTTP POST and pass the URL of the email attachment stored in Azure Blob Storage.

Setup is fairly straight forward, we need to:

* [Create a storage container in Azure](#creating-a-storage-container-in-azure)
* [Generate SAS URL allowing write access](#generate-sas-url-allowing-write-access)
* [Configure CloudMailin to send the attachments to Azure](#configure-cloudmailin-to-send-the-email-attachments-to-azure)

## Creating a storage container in Azure

First we need to head to the Azure portal and create a storage container:

![creating a storage container in azure screenshot](./assets/images/blog/azure/create_storage_container.png)

We need to head to the storage account section and then select containers from the menu.
In the new container dialog we'll need to name the container and leave the container as private.
We'll sort out CloudMailin permissions in the next step.

## Generate SAS URL allowing write access

In order to give CloudMailin access to the storage account and container we'll be using a
Shared Access Signature (or
[SAS URL](https://docs.microsoft.com/en-us/azure/storage/common/storage-sas-overview)).

![creating a SAS url screenshot](./assets/images/blog/azure/create_sas_url.png)

When creating the URL we'll need to give permissions to the Blob Objects and **only allow Write**
permissions. This is all that CloudMailin will need to upload files. We don't want permission to
be able to read the contents of the azure storage.

## Configure CloudMailin to send the email attachments to Azure

Finally we can now add the **full URL** to CloudMailin and the container name. Head to the
CloudMailin email address and add an 'attachment store'

![configuring CloudMailin Azure screenshot](./assets/images/blog/azure/configure_cloudmailin.png)

Now whenever CloudMailin receives and email with an attachment the attachment will be sent directly
to Azure Blob Storage for you to fetch.

More details aboout the exact format are in the CloudMailin
[HTTP POST Format Documentation](https://docs.cloudmailin.com/http_post_formats/multipart_normalized/).
In the noramlized multipart format we would see something like the following:

```c#
string url = Request.Form["attachments"][0]["url"];
```

The POSTed content includes the URL to the file, we can now fetch the file and download it:

The following are examples from the azure quickstart for listing and
[downloading blobs](https://docs.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-dotnet#download-blobs):

```c#
Console.WriteLine("Listing blobs...");

// List all blobs in the container
await foreach (BlobItem blobItem in containerClient.GetBlobsAsync())
{
    Console.WriteLine("\t" + blobItem.Name);
}
```

```c#
// Download the blob to a local file
// Append the string "DOWNLOAD" before the .txt extension
// so you can compare the files in the data directory
string downloadFilePath = localFilePath.Replace(".txt", "DOWNLOAD.txt");

Console.WriteLine("\nDownloading blob to\n\t{0}\n", downloadFilePath);

// Download the blob's contents and save it to a file
BlobDownloadInfo download = await blobClient.DownloadAsync();

using (FileStream downloadFileStream = File.OpenWrite(downloadFilePath))
{
    await download.Content.CopyToAsync(downloadFileStream);
    downloadFileStream.Close();
}
```

[create-storage]: https://assets.cloudmailin.com/assets/blog/azure/create_storage_container-c97029bd67ea511328d568c91f40d5a278b0e2dac02dd557e8aa823ebc95a66f.png
[create-sas-url]: https://assets.cloudmailin.com/assets/blog/azure/create_sas_url-bee2ab7755ea45b2799e5df7758685462a94e3a151003aa59c9575bb466dc1c2.png
[add-cloudmailin-storage]: https://assets.cloudmailin.com/assets/blog/azure/configure_cloudmailin-1875e57deb69b8cd8b45eb5bf573518ee3bc12c6d6b2f123aeba14b3212c7577.png

---

## Related articles

- [Receiving Email Attachments in AWS S3 is changing](https://www.cloudmailin.com/blog/receiving-email-attachments-in-s3-https)
- [Receiving email attachments in S3 compatible storage](https://www.cloudmailin.com/blog/receive-email-attachments-in-s3-compatible-storage)
- [Encrypted Full Email Storage / Backup API for AWS S3, Google Cloud Storage, Azure Blob](https://www.cloudmailin.com/blog/full-email-storage-api-in-aws-s3-azure-or-google)


---

*Originally published at https://www.cloudmailin.com/blog/receiving_email_and_attachments_on_azure by CloudMailin Team on 10 July 2020.*

*© 2026 CloudMailin.com, a product of Dynamic Edge Software Ltd.*

- All articles: https://www.cloudmailin.com/blog
- Documentation: https://docs.cloudmailin.com/
