I using flask and need send email
my code for it
from flask.ext.mail import Mail, Message
#mail config
app.config['MAIL_SERVER'] = 'smtp.gmail.com'
app.config['MAIL_PORT'] = 465
app.config['MAIL_USERNAME'] = '[email protected]'
app.config['MAIL_PASSWORD'] = 'mypassword'
app.config['MAIL_USE_TLS'] = False
app.config['MAIL_USE_SSL'] = True
mail = Mail(app)
"send" route
@app.route('/send/')
def send():
msg = Message('Hi', sender = '[email protected]', recipients = ['[email protected]'])
msg.body = "This is the email body sending with flask!"
mail.send(msg)
#msg.html = '<b>HTML</b> body'
return "Sent"
But after clicking on the above company I get the error
TypeError: __init__() takes 1 positional argument but 2 were given
File "I:pythonlibsite-packagesflaskapp.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "I:pythonlibsite-packagesflaskapp.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "I:pythonlibsite-packagesflaskapp.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "I:pythonlibsite-packagesflask\_compat.py", line 33, in reraise
raise value
File "I:pythonlibsite-packagesflaskapp.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "I:pythonlibsite-packagesflaskapp.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "I:pythonlibsite-packagesflaskapp.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "I:pythonlibsite-packagesflask\_compat.py", line 33, in reraise
raise value
File "I:pythonlibsite-packagesflaskapp.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "I:pythonlibsite-packagesflaskapp.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "G:flaskfopsterhello.py", line 56, in send
msg = Message('Hi', sender = '[email protected]', recipients = ['[email protected]'])
What could be the problem? The name of the mail addresses changed.
See Question&Answers more detail:
os