简体   繁体   中英

Emailing a file on an Azure blob storage

Every Monday, a file gets added to the Azure blob storage by a Timer triggered Function App. I'd like to know if there's a way to have it sent as an attachment to people over an email. The sender email would be my organization's and not GMail or Outlook or anything. The recipients would also be from my Organization.

All of the Function App code is written in Python, so it's a Linux environment and it's using a Consumption plan. I understand I cannot do a Sendgrid out binding, as it doesn't support Python (as of this writing).

I have gone through articles that talk about sending emails using MIMEMultipart, but the "attachment" it seeks from is a located locally. The files I am interested in are in the Azure storage account.

I've looked around immensely, but couldn't find anything that supports it. Since I am doing this on Python, I am all the more at loss.

Please, can you help me?

Long story short: I have a file on an Azure Storage account and using Python, I'd like to have it emailed to people.

You can create a new Azure Function with blob trigger.

Here's a sample about it:

def main(myblob: func.InputStream):
    logging.info(f"Python blob trigger function processed blob \n"
                 f"Name: {myblob.name}\n"
                 f"Blob Size: {myblob.length} bytes")

    img_data = myblob.read()

    #Logic to send the email in here

    try:
    except Exception as e:
        print('Error:')
        print(e)

Source: https://github.com/yokawasa/azure-functions-python-samples/tree/master/v2functions/blob-trigger-cosmosdb-out-binding

Another option, which I believe is easier, just use Logic Apps with Azure Storage Connector and your favorite tool to send the email (Sendgrid, outlook, gmail, etc)

https://docs.microsoft.com/bs-latn-ba/azure///////connectors/connectors-create-api-azureblobstorage

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM