Skip to content

Commit

Permalink
Merge 8170cf0 into 89d7f68
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasmassmann committed Apr 23, 2020
2 parents 89d7f68 + 8170cf0 commit 21182d6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 31 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Expand Up @@ -4,7 +4,8 @@ Changelog
5.0.0b2 (unreleased)
--------------------

- Nothing changed yet.
- Don't fail sending process when one email fails.
[thomasmassmann]


5.0.0b1 (2020-03-08)
Expand Down
71 changes: 41 additions & 30 deletions src/Products/EasyNewsletter/views/newsletter_issue_send.py
Expand Up @@ -132,48 +132,59 @@ def send(self):
# get issue data
issue_data = issue_data_fetcher()
for receiver in receivers:
personalized_html = issue_data_fetcher.personalize(
receiver, issue_data['body_html']
)
# get plain text version
personalized_plaintext = issue_data_fetcher.create_plaintext_message(
personalized_html
)

m = emails.Message(
html=personalized_html,
text=personalized_plaintext,
subject=issue_data['subject'],
mail_from=(sender_name, sender_email),
mail_to=(receiver['fullname'], receiver['email']),
)
m.transform(
images_inline=True,
base_url=self.context.absolute_url(),
cssutils_logging_level=logging.ERROR,
)
if 'HTTPLoaderError' in m.as_string():
log.exception(u"Transform message failed: {0}".format(m.as_string()))
send_status = {
'successful': None,
'error': None,
'datetime': datetime.now(),
}
try:
self.mail_host.send(m.as_string(), immediate=True)
send_status['successful'] = True
log.info('Send newsletter to "%s"' % receiver['email'])
send_counter += 1
except Exception as e: # noqa
personalized_html = issue_data_fetcher.personalize(
receiver, issue_data['body_html']
)
# get plain text version
personalized_plaintext = issue_data_fetcher.create_plaintext_message(
personalized_html
)

m = emails.Message(
html=personalized_html,
text=personalized_plaintext,
subject=issue_data['subject'],
mail_from=(sender_name, sender_email),
mail_to=(receiver['fullname'], receiver['email']),
)
m.transform(
images_inline=True,
base_url=self.context.absolute_url(),
cssutils_logging_level=logging.ERROR,
)
message_string = m.as_string()
if 'HTTPLoaderError' in message_string:
log.exception(u"Transform message failed: {0}".format(message_string))
try:
self.mail_host.send(message_string, immediate=True)
send_status['successful'] = True
log.info('Send newsletter to "%s"' % receiver['email'])
send_counter += 1
except Exception as e: # noqa
send_status['successful'] = False
send_status['error'] = e
log.exception(
'Sending newsletter to "%s" failed, with error "%s"!'
% (receiver['email'], e)
)
send_error_counter += 1
except Exception as e:
send_status['successful'] = False
send_status['error'] = e
log.exception(
'Sending newsletter to "%s" failed, with error "%s"!'
% (receiver['email'], e)
'Sending newsletter failed, with error "{0}"!'.format(e)
)
send_error_counter += 1
finally:
receiver['status'] = send_status
if not self.is_test:
receiver['status'] = send_status

# Add information to annotations
status_adapter = ISendStatus(self.context)
if status_adapter:
Expand Down

0 comments on commit 21182d6

Please sign in to comment.