D
D
DmitryRise2017-08-26 17:09:42
Django
DmitryRise, 2017-08-26 17:09:42

Why is django mail not being sent?

While working with sending letters, I encountered a problem, the message is not displayed, neither in the console, nor sent to the specified mailbox, tell me, please, what is the problem?

def send_email(request):
    settings = Settings.objects.first()

    if request.POST and request.is_ajax:
        name = request.POST.get('name')
        name_c = request.POST.get('name_c')
        phone = request.POST.get('phone')
        address = request.POST.get('address')
        message = request.POST.get('message')

        message = 'Имя: ' + str(name) + '\n' + 'Имя ребенка: ' + str(name_c) + '\n' + 'Phone: ' + str(phone) + '\n' + 'Адрес школы: ' + str(address) + '\n' + 'Сообщение: ' + str(message)

        if send_mail('Запись в школу', message, '[email protected]', [settings.email_main]):
            message_response = 'Ваше сообщение отправлено.'
        else:
            message_response = 'Сообщение не было отправлено, попробуйте еще раз.'
        return HttpResponse(message_response)

MAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.yandex.ru'
EMAIL_PORT = 465
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_USE_TLS = True
SERVER_EMAIL = EMAIL_HOST_USER
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question