At the moment I am creating new user accounts through the admin panel. When a new user is created, I set up a post save signal which will automatically send a welcome email to the new user’s registered email. My signals.py for this function looks like this:
#sends welcome email to new users with their username and default password
def send_welcome_email(sender,instance,created, **kwargs):
user=instance
template = render_to_string('accounts/welcome_email_template.html', {'name':user.first_name,'new_username':user.username,'default_password':user.password})
if created:
email = EmailMessage(
'Welcome to Isow Investors team' ,
template ,
settings.EMAIL_HOST_USER,
['an email address'],
)
email.fail_silently = False
email.send()
print("Welcome email sent to user")
post_save.connect(send_welcome_email, sender=User)
And this is an example of the email template that is sent to the user:
Hello {{name}},
Welcome to the team,
Below are the details you need to login for the first time. We highly recommend you to change your password after logging in for the first time. The link to change your password
can be found in your profile settings page.
username : {{new_username}}
default password : {{default_password}}
At the moment, when I create a new user, an email is sent to the user’s email successfully. The only issue I have is that instead of showing the default password that I registered their account with, I get what I assume to be the hashed password. A list of characters,symbols and numbers. So how can I include the default password in the welcome email so that the new user will be able to login for the first time? Thank You