python - No recipients have been added when trying to send message with Flask-Mail -
i trying send email flask-mail. create message recipients, assertionerror: no recipients have been added
when try send it. in following code, print out message recipients , correct. how fix error?
from flask import flask flask_mail import message, mail app = flask(__name__) app.config.update( debug=true, mail_server='smtp.gmail.com', mail_port=465, mail_use_ssl=true, mail_username='socialcreditsystem@gmail.com', mail_password='mypassword' ) mail = mail(app) @app.route('/') def hello_world(): msg=message('hey hey hey', sender='socialcreditsystem@gmail.com', recipients=['julian.fink1000@gmail.com']) print(msg.sender, msg.recipients) # ('socialcreditsystem@googlemail.com', ['julian.fink1000@googlemail.com']) print(msg.send_to) # set(['julian.fink1000@googlemail.com']) mail.send_message(msg) return 'hello world!' if __name__ == '__main__': app.run()
traceback (most recent call last): file "c:\python27\lib\site-packages\flask\app.py", line 1836, in __call__ return self.wsgi_app(environ, start_response) file "c:\python27\lib\site-packages\flask\app.py", line 1820, in wsgi_app response = self.make_response(self.handle_exception(e)) file "c:\python27\lib\site-packages\flask\app.py", line 1403, in handle_exception reraise(exc_type, exc_value, tb) file "c:\python27\lib\site-packages\flask\app.py", line 1817, in wsgi_app response = self.full_dispatch_request() file "c:\python27\lib\site-packages\flask\app.py", line 1477, in full_dispatch_request rv = self.handle_user_exception(e) file "c:\python27\lib\site-packages\flask\app.py", line 1381, in handle_user_exception reraise(exc_type, exc_value, tb) file "c:\python27\lib\site-packages\flask\app.py", line 1475, in full_dispatch_request rv = self.dispatch_request() file "c:\python27\lib\site-packages\flask\app.py", line 1461, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) file "c:\users\julian\pycharmprojects\flask_mail_test\flask_mail_test.py", line 26, in hello_world mail.send_message(msg) file "c:\python27\lib\site-packages\flask_mail.py", line 503, in send_message self.send(message(*args, **kwargs)) file "c:\python27\lib\site-packages\flask_mail.py", line 493, in send message.send(connection) file "c:\python27\lib\site-packages\flask_mail.py", line 428, in send connection.send(self) file "c:\python27\lib\site-packages\flask_mail.py", line 176, in send assert message.send_to, "no recipients have been added" assertionerror: no recipients have been added
you're using wrong function. mail.send_message
shortcut build , send message, takes same args message
. use mail.send(msg)
send existing message
instance.
Comments
Post a Comment