Esempio n. 1
0
def _send_mail(subject_line,
               body_text,
               sender_email,
               recipient_list,
               headers=None,
               attachments=None):
    """base send_mail function, which will attach email in html format
    if html email is enabled"""
    html_enabled = askbot_settings.HTML_EMAIL_ENABLED
    if html_enabled:
        message_class = mail.EmailMultiAlternatives
    else:
        message_class = mail.EmailMessage

    from askbot.models import User
    email_list = list()
    for recipient in recipient_list:
        if isinstance(recipient, User):
            email_list.append(recipient.email)
        else:
            email_list.append(recipient)

    msg = message_class(subject_line,
                        get_text_from_html(body_text),
                        sender_email,
                        email_list,
                        headers=headers,
                        attachments=attachments)
    if html_enabled:
        msg.attach_alternative(body_text, "text/html")

    msg.send()
Esempio n. 2
0
 def test_get_text_from_html(self):
     self.assertEqual(
         get_text_from_html(
             'ataoesa uau <a>link</a>aueaotuosu ao <a href="http://cnn.com">CNN!</a>\nnaouaouuau<img> <img src="http://cnn.com/1.png"/> <img src="http://cnn.com/2.png" alt="sometext">'
         ),
         u'ataoesa uau linkaueaotuosu ao http://cnn.com (CNN!)\n\nnaouaouuau http://cnn.com/1.png http://cnn.com/2.png (sometext)'
     )
Esempio n. 3
0
def _send_mail(subject_line, body_text, sender_email, recipient_list, headers=None, attachments=None):
    """base send_mail function, which will attach email in html format
    if html email is enabled"""
    html_enabled = askbot_settings.HTML_EMAIL_ENABLED
    if html_enabled:
        message_class = mail.EmailMultiAlternatives
    else:
        message_class = mail.EmailMessage

    from askbot.models import User
    email_list = list()
    for recipient in recipient_list:
        if isinstance(recipient, User):
            email_list.append(recipient.email)
        else:
            email_list.append(recipient)

    msg = message_class(
                subject_line,
                get_text_from_html(body_text),
                sender_email,
                email_list,
                headers=headers,
                attachments=attachments
            )
    if html_enabled:
        msg.attach_alternative(body_text, "text/html")

    msg.send()
Esempio n. 4
0
def _send_mail(subject_line, body_text, sender_email, recipient_list, headers=None):
    """base send_mail function, which will attach email in html format
    if html email is enabled"""
    html_enabled = askbot_settings.HTML_EMAIL_ENABLED
    if html_enabled:
        message_class = mail.EmailMultiAlternatives
    else:
        message_class = mail.EmailMessage

    msg = message_class(
                subject_line,
                get_text_from_html(body_text),
                sender_email,
                recipient_list,
                headers = headers
            )
    if html_enabled:
        msg.attach_alternative(body_text, "text/html")
    msg.send()
Esempio n. 5
0
def _send_mail(subject_line,
               body_text,
               sender_email,
               recipient_list,
               headers=None):
    """base send_mail function, which will attach email in html format
    if html email is enabled"""
    html_enabled = askbot_settings.HTML_EMAIL_ENABLED
    if html_enabled:
        message_class = mail.EmailMultiAlternatives
    else:
        message_class = mail.EmailMessage

    msg = message_class(subject_line,
                        get_text_from_html(body_text),
                        sender_email,
                        recipient_list,
                        headers=headers)
    if html_enabled:
        msg.attach_alternative(body_text, "text/html")
    msg.send()
Esempio n. 6
0
 def test_get_text_from_html(self):
     self.assertEqual(
         get_text_from_html('ataoesa uau <a>link</a>aueaotuosu ao <a href="http://cnn.com">CNN!</a>\nnaouaouuau<img> <img src="http://cnn.com/1.png"/> <img src="http://cnn.com/2.png" alt="sometext">'),
         u'ataoesa uau linkaueaotuosu ao http://cnn.com (CNN!)\n\nnaouaouuau http://cnn.com/1.png http://cnn.com/2.png (sometext)'
     )