smtplib рассылает за раз не все почты (максимум 100 почему то)
Использую aiosmptlib для рассылок в тг боте. При отправке за раз отправляется почему то только 100 писем максимум (в gmail в скрытой копии столько показывает). Респонс отправки говорит что слишком много получателей, хотя в лимитах gmail сказано, что до 500 в день, как это можно обойти?
Вот класс рассылки:
class MailingService():
def __init__(self) -> None:
self._client = SMTP(hostname='smtp.gmail.com', port=587)
async def connect(self, username: EmailStr, password: str) -> None:
await self._client.connect(
start_tls=True,
validate_certs=False,
username=username,
password=password,
)
async def send_email(self, sender: EmailStr, recipients: Sequence[EmailStr], email: MIMEMultipart) -> None:
async with self._client as client:
await client.sendmail(sender, recipients, email.as_string())
await client.quit()
async def attach_audio(self, audio_data: BytesIO, filename: str, email: MIMEMultipart) -> MIMEMultipart:
file = MIMEBase('audio', 'mp3')
file.set_payload(audio_data.read())
encoders.encode_base64(file)
file.add_header('content-disposition', 'attachment', filename=filename)
email.attach(file)
return email
async def compose_email(
self,
body: Optional[str],
subject: Optional[str],
sender: EmailStr,
email: MIMEMultipart
) -> MIMEMultipart:
email['Subject'] = subject
email['From'] = sender
email.attach(MIMEText(body, "plain", "utf-8"))
return email
хендлер:
for recipient_group in splitted_recipients:
email_id = await email_service.get_email_id(user_id=user_id, email=recipient_group[0])
audio_list = await audio_service.get_auto_mailing_audio(user_id=user_id, email_indexes=email_id)
user = await user_service.get_user(user_id=user_id)
msg = MIMEMultipart()
msg = await mailing_service.compose_email(
body=settings.email_text,
subject=settings.email_subject,
sender=user.personal_email,
email=msg
)
for audio in audio_list:
filename = audio.name
file = await bot.get_file(audio.file_id)
audio_data = await bot.download_file(file.file_path)
msg = await mailing_service.attach_audio(audio_data=audio_data, filename=filename, email=msg)
password = await user_service.get_user_password(user_id=user_id)
await mailing_service.connect(username=user.personal_email, password=password)
await mailing_service.send_email(sender=user.personal_email, recipients=recipient_group, email=msg)
sendmail response:
(452, b"4.5.3 Your message has too many recipients. For more information regarding\n4.5.3 Google's sending limits, go to\n4.5.3 https://support.google.com/mail/?p=TooManyRecipientsError - gsmtp")