Skip to content Skip to sidebar Skip to footer

Flask-mail And Redis Queue Library Integration Giving Error

I am using Flask-Mail extension to enable mail sending in the app. I was not able to get celery working with flask so I looked up some other library and found Redis Queue. Code:

Solution 1:

You're trying to enqueue the send method of the mail object instance and RQ can't enqueue instance methods. If you look at the documentation at the very bottom of the page it mentions this:

http://python-rq.org/docs/

Try defining another method and sending the mail that way. Such as...

from flask.ext.mail import Mail,Message
from rq import Queue

mail = Mail()
q = Queue()

defqueue_mail(msg):
    mail.send(msg)

@mod.route('/test')defm11():
    msg = Message("Signup Successfull",
                  recipients=['abc@gmail.com'])
    msg.body = "Hello there, Welcome!"
    q.enqueue(queue_mail, msg)
    return'done'

Post a Comment for "Flask-mail And Redis Queue Library Integration Giving Error"