Connection timed out error while sending mail from azure web app

2020-06-25T13:46:14.497+00:00

Hi,
I have created a flask app which sends mail to my colleagues in my organization. The mail client is outlook. My code is working properly and can send mail to the outlook email address but, once I deployed to azure web app, I am having issue of "Connection timed out error". I am using my company's SMTP relay service to send mail but, its failing somehow.

My azure web app is integrated with sub-net of Virtual network of azure web app and the IP address space of sub-net has been added into my company's SMTP relay service so that my web app can connect with the company's private network and send mail.

Can anyone suggest on the issue and how to resolve this.
I have mentioned the flask code below

from flask import Flask, render_template  
from flask_mail import Mail, Message  
  
app = Flask(__name__)  
app.config.update(  
    DEBUG=True,  
    MAIL_SERVER='COMPANY SMTP SERVER NAME',  
    MAIL_PORT=25,  
    MAIL_USERNAME='XXXXXX@ge.com'  
)  
mail = Mail(app)  
  
  
@app.route('/')  
def mailSend():  
    try:  
        msg = Message("Send Mail Tutorial!",  
                      sender="XXXXXX@ge.com",  
                      recipients=["YYYYY@ge.com"])  
        # msg.body = "Yo!\nHave you heard the good word of Python???"  
        # msg.html = render_template('text.html')  
        msg.html = render_template('thankyou.html')  
        mail.send(msg)  
        return 'Mail sent!'  
    except Exception as e:  
        print(type(e))  
        print(e)  
        return 'error'  

FYI, Dont want to use Sendgrid as SMTP relay server

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,913 questions
0 comments No comments
{count} votes

Accepted answer
  1. Manu Philip 18,681 Reputation points MVP
    2020-06-25T15:15:36.587+00:00

    Hello,

    In-order to send through your company's email server, you should have required connector created there which allows to send on behalf of your Azure App. In exchange server, you need a Receive connector which allows the Public IP address of your web app to send through the server. Similarly, check your company's email admin to create the necessary connector to send sucessfully

    Please mark as "Accept the answer" if the above steps helps you. Others with similar issues can also follow the solution as per your suggestion

    Regards,

    Manu

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

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.