Using SMTP on a Function App API

Ho, Keith D 120 Reputation points
2024-11-07T21:17:43.2433333+00:00

When I run the code below through that's on my API call, the code stops at the smtp_connection part. I'm able to run the API locally but when it is deployed on the Function App, it doesn't run through the smtp_connection line. Are there any settings I need to set up to allow this to go through?

        smtp_server = os.getenv("SMTP_SERVER")  
        smtp_port = 25  
        smtp_connection = smtplib.SMTP(smtp_server, smtp_port)  
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,194 questions
{count} votes

1 answer

Sort by: Most helpful
  1. JananiRamesh-MSFT 29,191 Reputation points
    2024-11-08T05:17:13.2033333+00:00

    @Ho, Keith D Thanks for reaching out. The preferred way to send e-mail from within Azure is through an SMTP relay service like the SendGrid Output binding: Azure Functions SendGrid bindings | Microsoft Learn , rather than sending e-mail directly from Azure Functions/ VMs etc

    Sending email on Port 25 is unsupported from all Azure Platform-as-a-Service (PaaS) resources, including Azure App Service and Azure Functions and it is blocked with most subscriptions

    please review this article for more information: Troubleshoot outbound SMTP connectivity in Azure | Microsoft Learn.

    do let me know incase of further queries, I would be happy to assist you.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.