Reputation: 39
This is my views file:
I have made a token file to generate a link
and info file for details like EMAIL_HOST_USER
and etc.
current_site = get_current_site(request)
email_subject = "Confirm your email @XYZ"
message2 = render_to_string('email_confirmation.html',{
'name': myuser.first_name,
'domain': current_site.domain,
'uid': urlsafe_base64_encode(force_bytes(myuser.pk)),
'token': generate_token.make_token(myuser),
})
email = EmailMessage(
email_subject,
message2,
settings.EMAIL_HOST_USER,
[myuser.email],
)
email.fail_silently=False
email.send()
Upvotes: 0
Views: 620
Reputation: 41
Had this same issue as well, but, it turned out that I was importing the EmailMessage
class.
Instead of doing this:
from email.message import EmailMessage
Use:
from django.core.mail import EmailMessage
Upvotes: 4
Reputation: 4710
EmailMessage(...)
[Django-doc] don't have any method named as send_mail()
it has to be send()
and EmailMessage
don't have any attribute named as fail_silently
it's a parameter passed to send()
method so finally your code will look like this
email = EmailMessage(
email_subject,
message2,
settings.EMAIL_HOST_USER,
[myuser.email],
)
email.content_subtype = "html" # can specify type of your content
email.send(fail_silently=True)
Upvotes: 0