Odesilani newsletteru po castech kvuli limitu API.
This commit is contained in:
parent
e0a735391b
commit
b0945a10d9
|
@ -391,9 +391,17 @@ def msg_send(request, id, realSend=False):
|
|||
}
|
||||
|
||||
if realSend:
|
||||
def chunks(l, n):
|
||||
"""Yield successive n-sized chunks from l."""
|
||||
for i in range(0, len(l), n):
|
||||
yield l[i:i + n]
|
||||
|
||||
from django.core.mail import get_connection, EmailMultiAlternatives
|
||||
import quopri
|
||||
|
||||
for recip_part in chunks(recipients_email, 500):
|
||||
# process by part, MailGun API hsa a limit of 1000 messages
|
||||
|
||||
mailgun_backend = get_connection('anymail.backends.mailgun.EmailBackend')
|
||||
|
||||
header_from = '%s <%s>' % (
|
||||
|
@ -417,7 +425,7 @@ def msg_send(request, id, realSend=False):
|
|||
eml = rcp.email
|
||||
ema.to = [ eml ]
|
||||
|
||||
ema.bcc = recipients_email
|
||||
ema.bcc = recip_part
|
||||
if obj.news.replyToEmail is not None:
|
||||
try:
|
||||
eml = obj.news.replyToEmail.strip()
|
||||
|
@ -433,6 +441,9 @@ def msg_send(request, id, realSend=False):
|
|||
ema.attach_alternative(html_message, "text/html")
|
||||
ema.send()
|
||||
|
||||
messages.info(request, "Zpráva odeslána %s uživatelům." % len(recip_part) )
|
||||
# end of partial send
|
||||
|
||||
if update_sent_ts:
|
||||
obj.sent_ts = datetime.now()
|
||||
obj.save()
|
||||
|
|
Loading…
Reference in New Issue