Fix news mailing
This commit is contained in:
parent
3d030c91fe
commit
6c47fb404b
|
|
@ -19,20 +19,24 @@ def send_email_with_news(news_ids):
|
||||||
.prefetch_related('subscription_type')
|
.prefetch_related('subscription_type')
|
||||||
sent_news = models.News.objects.filter(id__in=news_ids)
|
sent_news = models.News.objects.filter(id__in=news_ids)
|
||||||
|
|
||||||
htmly = get_template(settings.NEWS_EMAIL_TEMPLATE)
|
html_template = get_template(settings.NEWS_EMAIL_TEMPLATE)
|
||||||
year = datetime.now().year
|
year = datetime.now().year
|
||||||
|
|
||||||
socials = list(SiteSettings.objects.with_country().select_related('country'))
|
socials = list(SiteSettings.objects.with_country().select_related('country'))
|
||||||
socials = dict(zip(map(lambda social: social.country.code, socials), socials))
|
socials = dict(zip(map(lambda social: social.country.code, socials), socials))
|
||||||
|
|
||||||
for subscribe in subscribes.filter(unsubscribe_date=None):
|
for subscribe in subscribes.filter(unsubscribe_date=None):
|
||||||
|
subscriber = subscribe.subscriber
|
||||||
|
|
||||||
country = subscribe.subscription_type.country
|
country = subscribe.subscription_type.country
|
||||||
|
|
||||||
if country is None:
|
if country is None:
|
||||||
continue
|
country_code = subscriber.country_code
|
||||||
|
|
||||||
socials_for_subscriber = socials.get(country.code)
|
else:
|
||||||
subscriber = subscribe.subscriber
|
country_code = country.code
|
||||||
|
|
||||||
|
socials_for_subscriber = socials.get(country_code)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for new in sent_news:
|
for new in sent_news:
|
||||||
|
|
@ -52,9 +56,12 @@ def send_email_with_news(news_ids):
|
||||||
"year": year
|
"year": year
|
||||||
}
|
}
|
||||||
send_mail(
|
send_mail(
|
||||||
"G&M News", render_to_string(settings.NEWS_EMAIL_TEMPLATE, context),
|
subject="G&M News",
|
||||||
settings.EMAIL_HOST_USER, [subscriber.send_to], fail_silently=False,
|
message=render_to_string(settings.NEWS_EMAIL_TEMPLATE, context),
|
||||||
html_message=htmly.render(context)
|
from_email=settings.EMAIL_HOST_USER,
|
||||||
|
recipient_list=[subscriber.send_to],
|
||||||
|
fail_silently=False,
|
||||||
|
html_message=html_template.render(context)
|
||||||
)
|
)
|
||||||
except SMTPException:
|
except SMTPException:
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user