Venkatesh N
Venkatesh N

Reputation: 47

Send email in azure function under apps service plan

Im having azure function app with app service plan and I use python as programming lang. How can I send email from Azure functions... Is that possible with app service plan or do I need to choose third party services like "twilio grid" or please suggest the possibilities....

Upvotes: 0

Views: 2035

Answers (2)

SwethaKandikonda
SwethaKandikonda

Reputation: 8252

yes, you need to use Twilio SendGrid to send emails from azure functions. Alternatively, you can also switch to logic apps which provide many connectors including the one to send the mails

enter image description here

REFERENCES:

  1. Sending Email with Microsoft Azure
  2. Office 365 Outlook - Connectors

Upvotes: 1

Peter Bons
Peter Bons

Reputation: 29880

The easiest way is to use twilio sendgrid as it integrates very nicely with Azure Functions as an output binding using the SendGrid extension.

You can then create a function like

import logging
import json
import azure.functions as func

def main(req: func.HttpRequest, sendGridMessage: func.Out[str]) -> func.HttpResponse:

    value = "Sent from Azure Functions"

    message = {
        "personalizations": [ {
          "to": [{
            "email": "[email protected]"
            }]}],
        "subject": "Azure Functions email with SendGrid",
        "content": [{
            "type": "text/plain",
            "value": value }]}

    sendGridMessage.set(json.dumps(message))

    return func.HttpResponse(f"Sent")

See the docs for more details and the blogpost on twilio. There is a free plan to get started.

Using the Office 365 SMTP relay and Microsoft Graph API are also great options if you already have an Office 365 subscription. But it requires you to write the code yourself as there is no out-of-the box output binding.

Upvotes: 1

Related Questions