def send_email(self, notification): """ Sends an email notification """ assert hasattr(self, 'module') subject = _('{} - {} : {}').format(settings.ZDS_APP['site']['literal_name'], self.module, notification.title) from_email = _('{} <{}>').format(settings.ZDS_APP['site']['literal_name'], settings.ZDS_APP['site']['email_noreply']) receiver = self.user context = { 'username': receiver.username, 'title': notification.title, 'url': settings.ZDS_APP['site']['url'] + notification.url, 'author': notification.sender.username, 'site_name': settings.ZDS_APP['site']['literal_name'] } message_html = render_to_string( 'email/notification/' + convert_camel_to_underscore(self._meta.object_name) + '.html', context) message_txt = render_to_string( 'email/notification/' + convert_camel_to_underscore(self._meta.object_name) + '.txt', context) msg = EmailMultiAlternatives(subject, message_txt, from_email, [receiver.email]) msg.attach_alternative(message_html, 'text/html') try: msg.send() except SMTPException: LOG.error('Failed sending mail for %s', self, exc_info=True)
def send_email(self, notification): """ Sends an email notification """ assert hasattr(self, "module") subject = _("{} - {} : {}").format( settings.ZDS_APP["site"]["literal_name"], self.module, notification.title) from_email = _("{} <{}>").format( settings.ZDS_APP["site"]["literal_name"], settings.ZDS_APP["site"]["email_noreply"]) receiver = self.user # This can happen when a user subscribes via social networks without providing an e-mail address try: validate_email(receiver.email) except ValidationError: return context = { "username": receiver.username, "title": notification.title, "url": settings.ZDS_APP["site"]["url"] + notification.url, "author": notification.sender.username, "site_name": settings.ZDS_APP["site"]["literal_name"], } message_html = render_to_string( "email/notification/" + convert_camel_to_underscore(self._meta.object_name) + ".html", context) message_txt = render_to_string( "email/notification/" + convert_camel_to_underscore(self._meta.object_name) + ".txt", context) msg = EmailMultiAlternatives(subject, message_txt, from_email, [receiver.email]) msg.attach_alternative(message_html, "text/html") try: msg.send() except SMTPException: LOG.error("Failed sending mail for %s", self, exc_info=True)
def send_email(self, notification): """ Sends an email notification """ assert hasattr(self, 'module') subject = _('{} - {} : {}').format(settings.ZDS_APP['site']['literal_name'], self.module, notification.title) from_email = _('{} <{}>').format(settings.ZDS_APP['site']['literal_name'], settings.ZDS_APP['site']['email_noreply']) receiver = self.user # This can happen when a user subscribes via social networks without providing an e-mail address try: validate_email(receiver.email) except ValidationError: return context = { 'username': receiver.username, 'title': notification.title, 'url': settings.ZDS_APP['site']['url'] + notification.url, 'author': notification.sender.username, 'site_name': settings.ZDS_APP['site']['literal_name'] } message_html = render_to_string( 'email/notification/' + convert_camel_to_underscore(self._meta.object_name) + '.html', context) message_txt = render_to_string( 'email/notification/' + convert_camel_to_underscore(self._meta.object_name) + '.txt', context) msg = EmailMultiAlternatives(subject, message_txt, from_email, [receiver.email]) msg.attach_alternative(message_html, 'text/html') try: msg.send() except SMTPException: LOG.error('Failed sending mail for %s', self, exc_info=True)