def handle_noargs(self, **options): # Get unread conversations, which hasn't been read for one day unread_conversations = Conversation.objects.filter( unread_by__isnull=False, read_by_all__lt=now() - timedelta(days=1)) users = get_user_model().objects.filter( pk__in=unread_conversations.values_list('unread_by')).distinct() count = 0 for user in users: unread = unread_conversations.filter(unread_by__in=[user]).exclude( notified__in=[user]) if unread: count += 1 send_email( None, { 'user': user, 'conversations': unread, }, 'conversation/email/message_digest_subject.html', 'conversation/email/message_digest_body.html', settings.FROM_EMAIL, recipients=[user.email, ], priority='medium', ) for conversation in unread: conversation.notified.add(user) print('Sent {0} digest(s).'.format(count))
def save(self): if not self.cleaned_data.get('url'): self.instance.content_object = self.content_object obj = super(FeedbackForm, self).save() send_email( '', { 'url': reverse('admin:feedback_form_feedback_change', args=(obj.id, )), 'feedback': obj, }, 'feedback_form/email/subject.html', 'feedback_form/email/body.html', from_email=settings.FROM_EMAIL, recipients=[manager[1] for manager in settings.MANAGERS], ) if getattr(settings, 'FEEDBACK_EMAIL_CONFIRMATION', False): email = None if obj.email: email = obj.email elif obj.user.email: email = obj.user.email if email: send_email( '', {}, 'feedback_form/email/confirmation_subject.html', 'feedback_form/email/confirmation_body.html', from_email=settings.FROM_EMAIL, recipients=[email], ) return obj
def send_mail_to_user(self, email_context, to): """ Function to send the digest to the user. First we check the preffered email of the User instance. You can add this function in your defined User Profile. Therefore check Django's AUTH_PROFILE_MODULE setting. If you haven't defined this function or defined a Profile module the email of the User instance is used. """ email = to.email if hasattr(to, 'get_profile'): if hasattr(to.get_profile(), 'language'): activate(to.get_profile().language) if hasattr(to.get_profile(), 'get_preferred_email'): email = to.get_profile().get_preferred_email() if email: send_email( None, {'event_types': email_context}, 'object_events/email/subject.html', 'object_events/email/body.html', settings.FROM_EMAIL, [email], ) self.sent_emails += 1
def save(self): context = {} for info in self.cleaned_data: context.update({info: self.cleaned_data.get(info)}) send_email( None, context, self.subject_template, self.body_template, self.from_email, self.recipients, priority="medium", reply_to=self.cleaned_data.get('email', ''), ) # Empties the form self.data = {}
def save(self): if not self.cleaned_data.get('url'): self.instance.content_object = self.content_object obj = super(FeedbackForm, self).save() send_email( '', { 'url': reverse('admin:feedback_form_feedback_change', args=(obj.id, )), 'feedback': obj, }, 'feedback_form/email/subject.html', 'feedback_form/email/body.html', from_email=self.instance.email, recipients=[manager[1] for manager in settings.MANAGERS], ) return obj
def save(self): if not self.cleaned_data.get('url'): obj = super(FeedbackForm, self).save() send_email( '', { 'url': reverse('admin:feedback_form_feedback_change', args=(obj.id, )), 'email': obj.user or obj.email, 'date': obj.creation_date, 'message': obj.message, }, 'feedback_form/email/subject.html', 'feedback_form/email/body.html', 'feedback_form/email/body_plain.html', from_email=settings.FROM_EMAIL, recipients=[manager[1] for manager in settings.MANAGERS], ) return obj
def form_valid(self, form): self.object = form.save() if callable(settings.SUBSCRIBE_SUBJECT): subject = settings.SUBSCRIBE_SUBJECT(self.object) else: # pragma: no cover subject = settings.SUBSCRIBE_SUBJECT extra_context = { 'subscription': self.object, 'subject': subject, } send_email( self.request, extra_context, 'newsletter_signup/email/subscribe_subject.html', 'newsletter_signup/email/subscribe_body.html', settings.FROM_EMAIL, [self.object.email], ) return self.render_to_response(self.get_context_data( form=form, subscription=self.object))
def form_valid(self, form): self.object = form.instance if settings.VERIFICATION_REQUIRED: # if no verification was required to signup, then no verification # is required to unsubscribe if callable(settings.UNSUBSCRIBE_SUBJECT): subject = settings.UNSUBSCRIBE_SUBJECT(self.object) else: # pragma: no cover subject = settings.UNSUBSCRIBE_SUBJECT extra_context = { 'subscription': self.object, 'subject': subject, } send_email( self.request, extra_context, 'newsletter_signup/email/unsubscribe_subject.html', 'newsletter_signup/email/unsubscribe_body.html', settings.FROM_EMAIL, [self.object.email], ) form.delete() return self.render_to_response( self.get_context_data(form=form, subscription_deleted=True))