Answer the question
In order to leave comments, you need to log in
SMTPSenderRefused error. How to fix?
I am writing a bulk mailing program. Here is the code
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import smtplib
from email.mime.text import MIMEText
print('Войдите в свой аккаунт')
username = input("Username: ")
password = input("Password: ")
mail_sender = username
mail_receiver_input = input("Введите путь к файлу с адресами получателей: ")
header = input("Введите тему письма: ")
message_input = input("Введите путь к файлу с образцом письма: ")
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.ehlo()
try:
server.login(username, password)
except smtplib.SMTPAuthenticationError:
print("Неверный пароль или логин")
try:
for mail_receiver in open(mail_receiver_input, 'r'):
message = open(message_input, 'r').read()
mag = MIMEText(message, 'html', 'utf-8')
mag["Subject"] = header
mag['From'] = mail_sender
mag['To'] = mail_receiver
server.sendmail(mail_sender, mail_receiver, mag.as_string())
except FileNotFoundError:
print("Не найдено файла или папки")
server.quit()
smtplib.SMTPSenderRefused: (421, b'4.7.0 Try again later, closing connection. (MAIL) p89-v6sm20290047wrc.97 - gsmtp', '[email protected]')
Answer the question
In order to leave comments, you need to log in
Imap has nothing to do with it. Gmail will not let you send a lot of emails and will interfere with this in every possible way. Use a dedicated service.
By the way, if you configure DKIM, SPF and DMARC normally, then you can send using regular sendmail.
Go to the site solkogan.ru there is an article about sending mail through python where the author painted everything.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question