D
D
Dmitry2017-09-20 20:04:29
Django
Dmitry, 2017-09-20 20:04:29

Letters from the site on Django through Yandex do not reach. Where to dig?

Damn!!!
I'm trying to send password recovery emails from a Django forum via SMTP via smtp.yandex.ru. Mail for the domain is connected and configured. I checked sending from several machines (including the server) to several different mailboxes on Gmail, Mail.ru and Yandex. It comes to all mailboxes perfectly and instantly, it does not fall into "spam".
To celebrate, I dumped everything into production ... and it started! There was anger from users that the password recovery email did not reach! I myself have already driven the addresses of real registered users into the recovery form - they don’t reach, and that’s it!
Moreover, interestingly, some users were able to create new accounts on the forum and write to me about the problem, although when registering a new account, activation via mail is also required. Some said that activation falls in "Spam".
Prompt where to dig???
Here is the send config:

if True:
  # EMAIL_TIMEOUT = 5
  EMAIL_HOST = 'smtp.yandex.ru'
  EMAIL_PORT = 465
  # EMAIL_PORT = 587
  EMAIL_USE_SSL = True
  # EMAIL_USE_TLS = True
  EMAIL_HOST_USER = '[email protected]'
  EMAIL_HOST_PASSWORD = '*******'
  DEFAULT_FROM_EMAIL = 'Сайт.ру <%s>' % EMAIL_HOST_USER
  SERVER_EMAIL = EMAIL_HOST_USER

I read that it is necessary to send from TLS to port 587. Everything is the same: they reach me (on all boxes), users - no!
The MX record for the domain points to Yandex. I also registered a DKIM TXT record in DNS, which Yandex provides in pdd.yandex.ru. In short, the DNS settings are an exact copy of the DNS settings from pdd.yandex.ru.
Where else do you need to dig???

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry, 2017-09-21
@dimanjy

So far, I have implemented the digital signature of DKIM messages, as described in the manual https://djangosnippets.org/snippets/1995/ .
Let's see...
PS: The private part of the key is taken through the Yandex.Mail API.
UP 2 weeks later FOUND!
Well, who would have thought! Everything turned out to be ridiculously simple.
Looking at the Django source django.contrib.auth.forms.py in the PasswordResetForm class:

def get_users(self, email):
        ...
        return (u for u in active_users if u.has_usable_password())

It turns out that emails are only sent to users who have has_usable_password()!
Well, where will I get users with a valid password if I transferred them from a php forum, and I'm just trying to use the password recovery form to create valid passwords, damn it!???
That's why I was able to send letters to myself, because I have has_usable_password() == True, while everyone else has False.

R
rumsey, 2017-09-20
@rumsey

It worked for me with the following settings (now I send through my mailer):

EMAIL_HOST_YA = 'smtp.yandex.ru'
EMAIL_PORT_YA = 587
EMAIL_HOST_USER_YA = '[email protected]'
EMAIL_HOST_PASSWORD_YA = '1234'

And the send code:
from django.core.mail import get_connection, send_mail

#connections to yandex
connection = get_connection(
    host=settings.EMAIL_HOST_YA,
    port=settings.EMAIL_PORT_YA,
    username=settings.EMAIL_HOST_USER_YA,
    password=settings.EMAIL_HOST_PASSWORD_YA,
    use_tls=True
)
send_mail(
    subject,
    text_content,
    from_email,
    to,
    connection=connection,
    html_message=html_content
)

D
Dimonchik, 2017-09-20
@dimonchik2013

the number of letters per minute
and per day
limits, in short,
the exhaustive answer is very simple: washed for Yandex like Gmyl for Google - advertising and market share, therefore, if they stop using it, they will not be happy, therefore - tough antispam. It's one thing - meaningful letters from different addresses to different addresses (such as a regular corporate letter), another thing - use such technical
services, but there are completely free limits

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question