def send_notification(self, deliveries=[], email='', site_name='', fromemail='', template='', template_html=''): c_dict = {'site_name': site_name, 'deliveries': deliveries} c = Context(c_dict) subject = _(u"%(site_name)s - Stale shipments") % { 'site_name': site_name } from_field = "%s" % fromemail to_field = email t = loader.get_template(template) message = t.render(c) # match send_mail's signature send_mail_args = { 'subject': subject, 'message': message, 'from_email': from_field, 'recipient_list': [to_field], 'fail_silently': False, } try: kwargs = {} sending_store_mail.send(ship_notice_sender, send_mail_args=send_mail_args, \ context=c, **kwargs) except ShouldNotSendMail: return if not send_mail_args.get('recipient_list'): raise NoRecipientsException send_mail(**send_mail_args)
def send_notification(self, deliveries=[], email='', site_name='', fromemail='', template='', template_html=''): c_dict = { 'site_name': site_name, 'deliveries': deliveries } c = Context(c_dict) subject = _(u"%(site_name)s - Stale shipments") % { 'site_name': site_name} from_field = "%s" % fromemail to_field = email t = loader.get_template(template) message = t.render(c) # match send_mail's signature send_mail_args = { 'subject': subject, 'message': message, 'from_email': from_field, 'recipient_list': [to_field], 'fail_silently': False, } try: kwargs = {} sending_store_mail.send(ship_notice_sender, send_mail_args=send_mail_args, \ context=c, **kwargs) except ShouldNotSendMail: return if not send_mail_args.get('recipient_list'): raise NoRecipientsException send_mail(**send_mail_args)
def send_store_mail(subject, context, template='', recipients_list=None, format_subject=False, send_to_store=False, fail_silently=False, sender=None, **kwargs): """ :param subject: A string. :param format_subject: Determines whether the *subject* parameter is formatted. Only the %(shop_name)s specifier is supported now. :param context: A dictionary to use when rendering the message body. This overwrites an internal dictionary with a single entry, `shop_name`. :param template: The path of the plain text template to use when rendering the message body. :param `**kwargs`: Additional arguments that are passed to listeners of the signal :data:`satchmo_store.shop.signals.sending_store_mail`. """ from satchmo_store.shop.models import Config shop_config = Config.objects.get_current() shop_email = shop_config.store_email shop_name = shop_config.store_name if not shop_email: log.warn('No email address configured for the shop. Using admin settings.') shop_email = settings.ADMINS[0][1] c_dict = {'shop_name': shop_name} if format_subject: subject = subject % c_dict c_dict.update(context) c = Context(c_dict) recipients = recipients_list or [] if send_to_store: recipients.append(shop_email) # match send_mail's signature send_mail_args = { 'subject': subject, 'from_email': shop_email, 'recipient_list': recipients, 'fail_silently': fail_silently, } # let listeners modify context rendering_store_mail.send(sender, send_mail_args=send_mail_args, context=c, **kwargs) # render text email, regardless of whether html email is used. t = loader.get_template(template) body = t.render(c) # listeners may have set this entry if not 'message' in send_mail_args: send_mail_args['message'] = body try: # We inform listeners before checking recipients list, as they may # modify it. # Listeners may also choose to send mail themselves, so we place this # call in the SocketError try block to handle errors for them. try: sending_store_mail.send(sender, send_mail_args=send_mail_args, \ context=c, **kwargs) except ShouldNotSendMail: return if not recipients: raise NoRecipientsException send_mail(**send_mail_args) except SocketError, e: if settings.DEBUG: log.error('Error sending mail: %s' % e) log.warn("""Ignoring email error, since you are running in DEBUG mode. Email was: To: %s Subject: %s --- %s""" % (",".join(send_mail_args['recipient_list']), send_mail_args['subject'], send_mail_args['message'])) else: log.fatal('Error sending mail: %s' % e) raise IOError('Could not send email. Please make sure your email settings are correct and that you are not being blocked by your ISP.')
def send_store_mail(subject, context, template='', recipients_list=None, format_subject=False, send_to_store=False, fail_silently=False, sender=None, **kwargs): """ :param subject: A string. :param format_subject: Determines whether the *subject* parameter is formatted. Only the %(shop_name)s specifier is supported now. :param context: A dictionary to use when rendering the message body. This overwrites an internal dictionary with a single entry, `shop_name`. :param template: The path of the plain text template to use when rendering the message body. :param `**kwargs`: Additional arguments that are passed to listeners of the signal :data:`satchmo_store.shop.signals.sending_store_mail`. """ from satchmo_store.shop.models import Config shop_config = Config.objects.get_current() shop_email = shop_config.store_email shop_name = shop_config.store_name if not shop_email: log.warn( 'No email address configured for the shop. Using admin settings.') shop_email = settings.ADMINS[0][1] if shop_name: shop_email = "%s <%s>" % (shop_name, shop_email) c_dict = {'shop_name': shop_name} if format_subject: subject = subject % c_dict c_dict.update(context) c = c_dict recipients = recipients_list or [] if send_to_store: recipients.append(shop_email) # match send_mail's signature send_mail_args = { 'subject': subject, 'from_email': shop_email, 'recipient_list': recipients, 'fail_silently': fail_silently, } # let listeners modify context rendering_store_mail.send(sender, send_mail_args=send_mail_args, context=c, **kwargs) # render text email, regardless of whether html email is used. t = loader.get_template(template) body = t.render(c) # listeners may have set this entry if not 'message' in send_mail_args: send_mail_args['message'] = body try: # We inform listeners before checking recipients list, as they may # modify it. # Listeners may also choose to send mail themselves, so we place this # call in the SocketError try block to handle errors for them. try: sending_store_mail.send(sender, send_mail_args=send_mail_args, \ context=c, **kwargs) except ShouldNotSendMail: return if not send_mail_args.get('recipient_list'): raise NoRecipientsException send_mail(**send_mail_args) except SocketError, e: if settings.DEBUG: log.error('Error sending mail: %s' % e) log.warn( """Ignoring email error, since you are running in DEBUG mode. Email was: To: %s Subject: %s --- %s""" % (",".join(send_mail_args['recipient_list']), send_mail_args['subject'], send_mail_args['message'])) else: log.fatal('Error sending mail: %s' % e) raise IOError( 'Could not send email. Please make sure your email settings are correct and that you are not being blocked by your ISP.' )