Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Customizable send_mail #730

Merged
merged 5 commits into from Nov 6, 2017

Conversation

abulte
Copy link
Contributor

@abulte abulte commented Nov 6, 2017

Hi,

This pretty straightforward PR lets you override the send_mail method with your own logic. The override method is similar to render_template.

Thanks for considering this!


return app

Note that the above ``security.send_mail_task`` override will be useless if you
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you consider using .. note:: directive http://www.sphinx-doc.org/en/stable/markup/para.html#directive-note ?

app.config.from_object(config)

def custom_send_mail(subject, recipient, template, **context):
# implement your own logic here
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add an example when it would be necessary to override the send_mail method?

@abulte
Copy link
Contributor Author

abulte commented Nov 6, 2017

@jirikuncar I added an example. I hope it does not feel too contrived. My real world use case is too complex to be suitable for an example.


from flask import Flask
from flask_security import Security, SQLAlchemyUserDatastore
from flask.ext.emails import Message
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from flask_emails ...

@jirikuncar jirikuncar merged commit db9d04b into pallets-eco:develop Nov 6, 2017
@fuhrysteve
Copy link
Contributor

Thought I'd mention that I personally have been using this branch of Flask-Mail to override recipient in test environments via configuration: MAIL_CATCH_ALL = 'dev@mycompany.com'

pallets-eco/flask-mail#118

It seems to me that Flask-Mail should either be maintained, or dropped by Flask-Security

jwag956 referenced this pull request in Flask-Middleware/flask-security May 7, 2019
* Make send_mail function customizable.
jwag956 referenced this pull request in Flask-Middleware/flask-security May 7, 2019
* Customizable send_mail (#730)

* Make send_mail function customizable.

* Modified original commit to set send_mail and render_template as init configurations.

This is easier than subclassing Security and is the same as other overrides such as login_manager.

Updated docs.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants