Flask Email Not Sending
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 ap
Solution 1:
You're instantiating your model Message class and not the flask mail Message class.
Do something like :
from flask.ext.mail import Mail, Message as MailMessage
@app.route('/send/')defsend():
msg = MailMessage('Hi', sender = 'mymail@gmail.com', recipients = ['recipient@gmail.com'])
msg.body = "This is the email body sending with flask!"
mail.send(msg)
#msg.html = '<b>HTML</b> body'return"Sent"
Solution 2:
try to append this after the imports
app=Flask(__name__)
You are not initialising the app.Go through this document here to learn in detail.
Solution 3:
Check this.
from flask import Flask
from flask_mail import Mail, Message
app = Flask(__name__)
mail=Mail(app)
app.config['MAIL_SERVER']='smtp.gmail.com'
app.config['MAIL_PORT'] = 465
app.config['MAIL_USERNAME'] = 'your_email'
app.config['MAIL_PASSWORD'] = 'your_password'
app.config['MAIL_USE_TLS'] = False
app.config['MAIL_USE_SSL'] = True
app.config['MAIL_DEFAULT_SENDER'] = 'default_sender_email'
app.config['MAIL_ASCII_ATTACHMENTS'] = True
app.config['DEBUG'] = True
mail = Mail(app)
@app.route("/send")defindex():
try:
msg = Message('Subject', recipients = ['reciever_mail_id'])
msg.body = "Hello Flask message sent from Flask-Mail"
msg.html = "<b>TESTING HTML TAG</b>"
mail.send(msg)
except Exception as e:
raise e
return"Check Your Inbox !!!"if __name__ == '__main__':
app.run(debug = True)
Post a Comment for "Flask Email Not Sending"