I am sending an email to regenerate password to newly created Users.
The argument user takes an instance of User.
def password_mail(user):
user_email = user.email
first_name = user.first_name
token = token_generator.make_token(user)
uid = urlsafe_base64_encode(force_bytes(user.pk))
domain = Site.objects.get_current().domain
sg = sendgrid.SendGridAPIClient(apikey=SENDGRID_API_KEY)
from_email = Email('[email protected], 'My Domain')
to_email = user_email
subject = 'Account Creation'
ctx = {
'first_name': first_name,
'domain': domain,
'uid': uid,
'token': token,
'validlink': True
}
html_content = render_to_string('accounts/user_mail_password.html', ctx)
content = Content("text/html", html_content)
mail = Mail(from_email, subject, to_email, content)
response = sg.client.mail.send.post(request_body=mail.get())
I get no mail sent and this error message. Thanks.
File "/Users/aureliendebord/Python/myapp/app/utils.py", line 76, in password_mail
mail = Mail(from_email, subject, to_email, content)
File "/Users/aureliendebord/Python/myapp/myvenv/lib/python3.6/site-packages/sendgrid/helpers/mail/mail.py", line 31, in __init__
personalization.add_to(to_email)
File "/Users/aureliendebord/Python/myapp/myvenv/lib/python3.6/site-packages/sendgrid/helpers/mail/mail.py", line 523, in add_to
self._tos.append(email.get())
AttributeError: 'str' object has no attribute 'get'
My bad. Forget to use the Email() on user_email.
Closed.
Thanks for providing an update @aureliendebord!
Most helpful comment
My bad. Forget to use the Email() on user_email.
Closed.