1

Can I use mandrill modules for Flask-security mails?

I know flask-security is using Flask-mail module but I want to use mandrill instead.

Bhargav Patel
  • 151
  • 2
  • 10

1 Answers1

2

Use flask-mandrill, and make flask-security send its emails using it:

from flask.ext.mandrill import Mandrill

app = Flask(__name__)
app.config['MANDRILL_API_KEY'] = 'your api key'
app.config['MANDRILL_DEFAULT_FROM'] = 'admin@yourdomain.com'

mandrill = Mandrill(app)

@security.send_mail_task
def send_email(msg):
    mandrill.send_email(
        from_email=msg.sender,
        subject=msg.subject,
        to=map(lambda recipient: {'email': recipient}, msg.recipients),
        html=msg.html
    )
imriqwe
  • 1,455
  • 11
  • 15
  • 1
    map() in Python 3 is a generator function, which is not serializeable in JSON. Wrapping it in a list can resolve: `to=list(map(lambda recipient: {'email': recipient}, msg.recipients)), html=msg.html` – Bob Jordan Oct 05 '17 at 14:12
  • How to add cc email id – Ganesan J Jun 09 '21 at 05:34