0

I'm trying to send a email for users. In one situation it sends, but in other didn't send. If I use 'email_user' it sends the email. 'user' is an autentificated user (built in with django). About 'send_mail' I know after reading the documentation.

current_site = get_current_site(request)
subject = 'Activate Your Account'
message = render_to_string('account_activation_email.html', {
    'user': user,
    'domain': current_site.domain,
    'uid': urlsafe_base64_encode(force_bytes(user.pk)),
    'token': account_activation_token.make_token(user),
})
user.email_user(subject, message)
return redirect('account_activation_sent')

But when I want to use send_mail instead of email_user, it's not working. I want to understand what I do wrong.

send_mail(subject, message, email_from, recipient_list, fail_silently=False)

My settings:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
DEFAULT_FROM_EMAIL = get_secret('EMAIL_HOST_USER')

EMAIL_HOST = get_secret('EMAIL_HOST')
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = get_secret('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = get_secret('EMAIL_HOST_PASSWORD')
# Custom setting. To email
RECIPIENT_ADDRESS = ['None']
Sergo
  • 93
  • 3
  • 10
  • 1
    You have not given proper code, please first give proper and complete relevant code so we can help you, like what is user here, is send_mail an inbuilt Django function or a custom function? – Divya Prakash Jul 22 '22 at 20:09
  • @rkisdp, user and send_mail - all inbuilt Django. – Sergo Jul 22 '22 at 20:11
  • 1
    and can you please show the instance of user? – Divya Prakash Jul 22 '22 at 20:12
  • rkisdp, I can't. It's inbuilt Django. https://docs.djangoproject.com/en/4.0/topics/auth/default/#user-objects – Sergo Jul 22 '22 at 20:24
  • 1
    please, if you have send_mail(... fail_silently=False), provide us with error information. – Maxim Danilov Jul 22 '22 at 20:27
  • 1
    @Sergo but from where you are getting email_user in the user object, email_user isn't the default function of django. can you show from where you are importing user, please? – Divya Prakash Jul 22 '22 at 20:39
  • 1
    @rkisdp - Sergo ask us about send_mail, not about email_user. – Maxim Danilov Jul 22 '22 at 20:51
  • Divya Prakash, no, it's inbuilt (https://docs.djangoproject.com/en/4.0/topics/auth/default/#user-objects). Maxim Danilov, I haven't any errors. – Sergo Jul 23 '22 at 07:52
  • @Divya Prakash, sorry I got you wrong link. But the 'email_user' is inbuilt to django. You can look at (https://docs.djangoproject.com/en/4.1/ref/contrib/auth/#django.contrib.auth.models.User.email_user). And I edited the question. You ranked down it, can you please rank up it please now? Thank you. – Sergo Aug 07 '22 at 15:13
  • 1
    @Sergo sorry but I didn't rank it. I don't know who did that, still, I have upvoted it for you. – Divya Prakash Aug 07 '22 at 18:26
  • @Divya Prakash, oh, I'm sorry, and thank you for your kindness.) – Sergo Aug 08 '22 at 09:35

1 Answers1

0

I understand what happened. send_mail is working only with EMAIL_HOST which provided by gmail. But when I want to send email to another email_service, then it's working with email_user. Thanks for all.

Sergo
  • 93
  • 3
  • 10