ModuleNotFoundError: No module named 'flask_mail'

2020-06-26T15:37:18.83+00:00

Hi,

i have created a new azure web app and deployed the below mentioned flask code to the app using azure cli command from my local computer. Right now, while running the app its throwing error that "ModuleNotFoundError: No module named 'flask_mail'"
I already installed requirement.txt and flask-mail is also mentioned over there. any idea why its showing now ?

 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.html = render_template('thankyou.html')
          mail.send(msg)
          return 'Mail sent!'
      except Exception as e:
          print(type(e))
          print(e)
          return 'error'

@ryanchill if you have any suggestion please let me know.

FYI, I already deployed this code before as well to another web app and that time though it didn't send any mail but it didnt throw any error like this.

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

1 answer

Sort by: Most helpful
  1. Ryan Hill 26,771 Reputation points Microsoft Employee
    2020-07-01T14:37:48.92+00:00

    Hi @MITRADebarthaGECoreTechCyber-2843,

    According to https://pythonhosted.org/flask-mail/, I don't believe flask_mail is an available module in the Mail package. Hope that helps.

     from flask import Flask
     from flaskext.mail import Mail
        
     app = Flask(__name__)
     mail = Mail(app)
    

    Regards,
    Ryan

    0 comments No comments