-1

OSError: [Errno 2] No such file or directory when i try send a mail by using flask_mail. Below is my code:

       app.config['MAIL_SERVER']='smtp.gmail.com'
       app.config['MAIL_PORT'] = 465
       app.config['MAIL_USERNAME'] = parametter.email_sender
       app.config['MAIL_PASSWORD'] = parametter.email_sender_password
       app.config['MAIL_USE_TLS'] = False
       app.config['MAIL_USE_SSL'] = False
       mail = Mail(app)
      @app.route('/')
      def main():
               msg = Message('Hello', sender = parametter.email_sender,recipients = [parametter.email_recipients])
               msg.body = "Hello Flask message sent from Flask-Mail"
               mail.send(msg)
               return "Sent"

When I comment(#mail.send(msg)), the program run normal. But i can't send the message. Can anyone help me with this question,please?

davidism
  • 121,510
  • 29
  • 395
  • 339

1 Answers1

0

It's wrong when I import library:

from flask.ext.mail import Mail, Message

It should be:

from flask_mail import Mail, Message