Skip to content

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

@ariroffe

Description

@ariroffe

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions