Tell me, please, how can I send letters from any addressee? I have the following settings in .settings.py
EMAIL_HOST = 'smtp.yandex.ru' EMAIL_HOST_USER = 'yandexUser' EMAIL_HOST_PASSWORD = 'secretPassword' EMAIL_PORT = 587 EMAIL_USE_TLS = True Next in the shell, the following code works
send_mail('Django mail', 'This e-mail was send with Django.', 'yandexUser@ya.ru', ['mySecondMail@gmail.com'], fail_silently=False)
But this does not work
send_mail('Django mail', 'This e-mail was send with Django.', 'info@any-site.ru', ['mySecondMail@gmail.com'], fail_silently=False)
I have no problems with php, I also use Yandex or Google as a mail server, and I substitute any address as an addressee.
It turned out to do this:
import smtplib def sendMail(email_from, email_to, subject, text): server = smtplib.SMTP("smtp.yandex.ru", 587) server.ehlo() server.starttls() server.login("myYandexAccount", "o_MyPassword") message = "\r\n".join([ \ "From: {}".format(email_from), \ "To: {}".format(email_to), \ "Subject: {}".format(subject), \ "", \ "{}".format(text) \ ]) server.sendmail("myYandexAccount@ya.ru", email_to, message) server.quit() sendMail( 'email_from@gmail.com', 'email_to@gmail.com', 'subject message', 'body text here...' )
send_mail('Django mail', 'This e-mail was send with Django.', 'test@gmail.com', ['myemail@gmail.com'], fail_silently=False)- wedocaTraceback (most recent call last): ... smtplib.SMTPSenderRefused: (553, b'5.7.1 Sender address rejected: not owned by auth user.', 'test@gmail.com')- wedoca