def send_email(self):
        profiles = UserProfile.objects.filter(notify_by_email=True)
        recipients = [p.user.email for p in profiles]

        subject = '[{0}]: {1}'.format(self.site.name, self.entry.title)
        body = self.render_template('blog/notification_email.html')
        message = EmailMultiAlternatives(subject,
                                         body,
                                         settings.DEFAULT_FROM_EMAIL,
                                         [settings.DEFAULT_FROM_EMAIL],
                                         recipients)
        message.mixed_subtype = "related"
        try:
            body_html = self.render_template('blog/notification_email_html.html')

            soup = BeautifulSoup(body_html)
            images = {}
            for index, tag in enumerate(soup.findAll(self._image_finder)):
                if tag['src'] not in images.keys():
                    images[tag['src']] = "image_{0}".format(index)
                tag['src'] = 'cid:{0}'.format(images[tag['src']])

            body_html = str(soup)

            for filename, file_id in images.items():
                image_file = self._file_finder(filename)
                if image_file:
                    msg_image = MIMEImage(image_file.read())
                    image_file.close()
                    msg_image.add_header('Content-ID', '<{0}>'.format(file_id))
                    message.attach(msg_image)

            message.attach_alternative(body_html, "text/html")

        except Exception, e:
            raise e
            # if we can't load the html template or related images,
            # don't send the HTML version
            pass

        message.send()
dataset/ETHPy150Open mpirnat/hackday/hackday/blog/notifications.py/BlogNotification.send_email/original