Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the posibility of sending emails to an address different than user.email #87

Open
ariroffe opened this issue Nov 23, 2023 · 1 comment

Comments

@ariroffe
Copy link

ariroffe commented Nov 23, 2023

Hello, once again, thanks for the great work put into this package, I think it is really neat.

So, I'd like my users to be able to change their registered email, but I want to verify their new email account before the change takes place. One way I figured I could do that was by saving the requested new email in a different field (say, new_email), then send a verification link to that new address, and have the callback just do user.email = user.new_email in case the user is_active and has the new_email field set. The issue is that send_email only allows me to send emails to user.email.

I think there is an easy fix for this that doesn't break existing code. It would just require changing the signature of send_email from:

def send_email(user, thread=True, expiry=None, context=None):

to:

def send_email(user, thread=True, expiry=None, context=None, address=None):

and then in send_inner_thread changing the line:

msg = EmailMultiAlternatives(subject, text, sender, [user.email])

to:

to = address or user.email
msg = EmailMultiAlternatives(subject, text, sender, [to])

(of course, the new address parameter would need to be propagated to send_inner_thread).
That way send_email(user) and send_email(user, address=user.new_email) would both work.

Do you think that this is possible/desirable? If so, would you like me to do a PR or would you prefer to change it yourself?

@ariroffe
Copy link
Author

ariroffe commented Nov 23, 2023

Edit: From what I understand, the solution I proposed would not require changing the payload in the token generator, but the email field would still need to be set for the user, with the old value, when the email is sent.

Maybe instead of modifying the signature of send_email one could provide a new function send_change_email (or something like that) to make the API clearer.

Another possibility would be to provide the name of the field in the user model to send the email to, but that sounds like it should be done with a setting (and require a change in the payload), and would not fit my use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant