i use code:
from django.db.models.signals import post_save
from django.dispatch import receiver
from ...models import User as midas_user
from django.core.mail import send_mail
from django.conf import settings
import logging
logger = logging.getLogger(__name__)
@receiver(post_save, sender=midas_user)
def create_user_profile(sender, instance, created, **kwargs):
if created:
logger.info("New user created: %s", instance.name)
send_mail("midas_user.instance",
"Here is the message",
"[email protected]",
["[email protected]"]
)
my settings:
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = "[email protected]"
EMAIL_HOST_PASSWORD = 'i change this string'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
if i try to create user i have error:
shop-backend-back | File "/usr/local/lib/python3.8/smtplib.py", line 640, in auth
shop-backend-back | (code, resp) = self.docmd("AUTH", mechanism + " " + response)
shop-backend-back | File "/usr/local/lib/python3.8/smtplib.py", line 430, in docmd
shop-backend-back | return self.getreply()
shop-backend-back | File "/usr/local/lib/python3.8/smtplib.py", line 403, in getreply
shop-backend-back | raise SMTPServerDisconnected("Connection unexpectedly closed")
shop-backend-back | smtplib.SMTPServerDisconnected: Connection unexpectedly closed
i just first time try yo use send_mail and take this. how to fix it?
To use Gmail like this, you will need to follow the instructions shown here:
https://support.google.com/mail/thread/40988320?hl=en
As written there:
This article also includes some further troubleshooting steps.
But it is clear from your error, this is not a python issue.