def send_mail(subject, message, from_email, recipient_list, priority="medium", fail_silently=False, auth_user=None, auth_password=None): from django.utils.encoding import force_unicode from mailer.models import Message from mailer import PRIORITY_MAPPING priority = PRIORITY_MAPPING[priority] # need to do this in case subject used lazy version of ugettext subject = force_unicode(subject) message = force_unicode(message) if len(subject) > 100: subject = u"%s..." % subject[:97] for to_address in recipient_list: message = Message( to_address=to_address, from_address=from_email, subject=subject, message_body=message, priority=priority ) message.save() return message
def send_mail(subject, message, from_email, recipient_list, priority="medium", fail_silently=False, auth_user=None, auth_password=None): from django.utils.encoding import force_unicode from mailer.models import Message from mailer import PRIORITY_MAPPING priority = PRIORITY_MAPPING[priority] # need to do this in case subject used lazy version of ugettext subject = force_unicode(subject) message = force_unicode(message) if len(subject) > 100: subject = u"%s..." % subject[:97] for to_address in recipient_list: message = Message(to_address=to_address, from_address=from_email, subject=subject, message_body=message, priority=priority) message.save() return message
def send_mail(subject, message, from_email, recipient_list, priority="medium", fail_silently=False, auth_user=None, auth_password=None, headers={}, attachments=None): """ Function to queue e-mails """ from django.utils.encoding import force_text from django.core.mail import EmailMessage from mailer.models import Message, PRIORITY_MAPPING priority = PRIORITY_MAPPING[priority] subject = force_text(subject) message = force_text(message) email_obj = EmailMessage(subject=subject, body=message, from_email=from_email, to=recipient_list, attachments=attachments, headers=headers) db_msg = Message(priority=priority, subject=subject) db_msg.email = email_obj db_msg.set_recipients(recipient_list) db_msg.save() return db_msg return 1
def send_mail(subject, message, from_email, recipient_list, priority="medium", fail_silently=False, auth_user=None, auth_password=None, headers={}, attachments=None): """ Function to queue e-mails """ from django.utils.encoding import force_text from django.core.mail import EmailMessage from mailer.models import Message, PRIORITY_MAPPING priority = PRIORITY_MAPPING[priority] subject = force_text(subject) message = force_text(message) email_obj = EmailMessage( subject=subject, body=message, from_email=from_email, to=recipient_list, attachments=attachments, headers=headers ) db_msg = Message( priority=priority, subject=subject ) db_msg.email = email_obj db_msg.set_recipients(recipient_list) db_msg.save() return db_msg return 1
def send_html_mail(subject, message, message_html, from_email, recipient_list, priority="medium", fail_silently=False, auth_user=None, auth_password=None, headers={}, attachments=None): """ Function to queue HTML e-mails """ from django.utils.encoding import force_text from django.core.mail import EmailMultiAlternatives from mailer.models import Message, PRIORITY_MAPPING priority = PRIORITY_MAPPING[priority] # need to do this in case subject used lazy version of ugettext subject = force_text(subject) message = force_text(message) message_html = force_text(message_html) email_obj = EmailMultiAlternatives( subject=subject, body=message, from_email=from_email, to=recipient_list, attachments=attachments, headers=headers ) email_obj.attach_alternative(message_html, "text/html") db_msg = Message( priority=priority, subject=subject ) db_msg.email = email_obj db_msg.set_recipients(recipient_list) db_msg.save() return 1
def send_mail(subject, message, from_email, recipient_list, priority="medium", fail_silently=False, auth_user=None, auth_password=None, html_body="", attachments=None): """ Puts a new email on the queue. See the documentation for django.core.mail.send_mail for more information on the basic options. You can add attachments by passing a list of tuples to the attachments keyword argument. The tuples must have the following structure: (filename, bytes, mimetype or None) e.g. ('filename.txt', 'raw bytestring', 'application/octet-stream') """ from django.conf import settings from django.utils.encoding import force_unicode from mailer.models import Message # need to do this in case subject used lazy version of ugettext subject = force_unicode(subject) priority = PRIORITY_MAPPING[priority] if from_email is None: from_email = settings.DEFAULT_FROM_EMAIL for to_address in recipient_list: msg = Message(to_address=to_address, from_address=from_email, subject=subject, message_body=message, html_body=html_body, priority=priority, ready_to_send=False) msg.save() _add_attachments(msg, attachments)
def send_mail( subject, message, from_email, recipient_list, priority="medium", fail_silently=False, auth_user=None, auth_password=None, schedule=None, content_subtype="plain", ): from django.utils.encoding import force_unicode from mailer.models import Message # need to do this in case subject used lazy version of ugettext subject = force_unicode(subject) priority = PRIORITY_MAPPING[priority] for to_address in recipient_list: m = Message( to_address=to_address, from_address=from_email, subject=subject, message_body=message, priority=priority, content_subtype=content_subtype, ) if schedule: m.schedule = schedule m.save()
def send_messages(self, email_messages): num_sent = 0 for email in email_messages: msg = Message() msg.email = email msg.save() num_sent += 1 return num_sent
def send_messages(self, email_messages): num_sent = 0 subject_prefix = getattr(settings, 'MAILER_EMAIL_SUBJECT_PREFIX', None) for email in email_messages: if subject_prefix: email.subject = u'%s %s' % (_(subject_prefix), email.subject) msg = Message() msg.email = email msg.save() num_sent += 1 return num_sent
def send_messages(self, email_messages): num_sent = 0 for email in email_messages: email.subject = email.subject.encode('utf-8') email.body = email.body.encode('utf-8') msg = Message() msg.email = email msg.save() num_sent += 1 return num_sent
def send_messages(self, email_messages): try: num_sent = 0 for email in email_messages: msg = Message() msg.email = email msg.save() num_sent += 1 return num_sent except Exception: if BACKUP_BACKEND: return BACKUP_BACKEND.send_messages(email_messages) else: raise
def mail_managers(subject, message, fail_silently=False, priority="medium", attachments=None): from django.utils.encoding import force_unicode from django.conf import settings from mailer.models import Message priority = PRIORITY_MAPPING[priority] for name, to_address in settings.MANAGERS: msg = Message(to_address=to_address, from_address=settings.SERVER_EMAIL, subject=settings.EMAIL_SUBJECT_PREFIX + force_unicode(subject), message_body=message, priority=priority, ready_to_send=False) msg.save() _add_attachments(msg, attachments)
def send_html_mail(subject, message, message_html, from_email, recipient_list, priority='medium', fail_silently=False, auth_user=None, auth_password=None, headers=None, attachments=None, content_object=None, tag=None, reply_to_list=None): """ Function to queue HTML e-mails """ from django.utils.encoding import force_text from django.core.mail import EmailMultiAlternatives from mailer.models import Message, PRIORITY_MAPPING headers = headers or {} priority = PRIORITY_MAPPING[priority] # need to do this in case subject used lazy version of ugettext subject = force_text(subject) message = force_text(message) message_html = force_text(message_html) email_obj = EmailMultiAlternatives(subject=subject, body=message, from_email=from_email, to=recipient_list, attachments=attachments, headers=headers, reply_to=reply_to_list) email_obj.attach_alternative(message_html, 'text/html') db_msg = Message(priority=priority, subject=subject, content_object=content_object, tag=tag) db_msg.email = email_obj db_msg.set_recipients(recipient_list) db_msg.set_reply_to(reply_to_list) db_msg.save() return db_msg
def send_html_mail(subject, message, message_html, from_email, recipient_list, recipient_bcc_list, priority="medium", fail_silently=False, auth_user=None, auth_password=None): """ Function to queue HTML e-mails """ from django.utils.encoding import force_unicode from django.core.mail import EmailMultiAlternatives from mailer.models import make_message, Message priority = PRIORITY_MAPPING[priority] db_msg = Message(priority="0") db_msg.save() # need to do this in case subject used lazy version of ugettext subject = force_unicode(subject) message = force_unicode(message) # substitute in the message id for tracking message = message.format(id=db_msg.id) message_html = message_html.format(id=db_msg.id) msg = make_message(subject=subject, body=message, from_email=from_email, to=recipient_list, bcc=recipient_bcc_list, priority=priority) email = msg.email email = EmailMultiAlternatives(email.subject, email.body, email.from_email, email.to, email.bcc) email.attach_alternative(message_html, "text/html") db_msg.email = email db_msg.priority = priority db_msg.save() return db_msg