def clean(self): data = self.cleaned_data # check if email host relay is properly set up if not is_newsletter_relay_set(): raise forms.ValidationError(_('Email relay is not configured properly.' ' Newsletter cannot be sent.')) return data
def clean(self): data = self.cleaned_data # check if email host relay is properly set up if not is_newsletter_relay_set(): raise forms.ValidationError(_('Email relay is not configured properly.' ' Newsletter cannot be sent.')) return data
def dispatch(self, request, *args, **kwargs): pk = int(kwargs.get("pk")) newsletter = get_object_or_404(Newsletter, pk=pk) if newsletter.send_status == "draft": return redirect(reverse("newsletter.action.step4", kwargs={"pk": newsletter.pk})) elif newsletter.send_status == "sending" or newsletter.send_status == "resending": return redirect(reverse("newsletter.detail.view", kwargs={"pk": newsletter.pk})) if not is_newsletter_relay_set(): messages.error(request, _("Email relay is not configured properly." " Newsletter cannot be sent.")) return redirect(reverse("newsletter.detail.view", kwargs={"pk": newsletter.pk})) return super(NewsletterResendView, self).dispatch(request, *args, **kwargs)
def clean(self): data = self.cleaned_data # check if email host relay is properly set up if not is_newsletter_relay_set(): raise forms.ValidationError( _('Email relay is not configured properly.' ' Newsletter cannot be sent.')) if 'schedule_send' in data and data['schedule_send']: if not 'schedule_send_dt' in data or not data['schedule_send_dt']: raise forms.ValidationError( _("You've checked Schedule to Send, please also pick a date and time to send." )) return data
def dispatch(self, request, *args, **kwargs): pk = int(kwargs.get('pk')) newsletter = get_object_or_404(Newsletter, pk=pk) if newsletter.send_status == 'draft': return redirect(reverse('newsletter.action.step4', kwargs={'pk': newsletter.pk})) elif newsletter.send_status == 'sending' or newsletter.send_status == 'resending': return redirect(reverse('newsletter.detail.view', kwargs={'pk': newsletter.pk})) if not is_newsletter_relay_set(): messages.error(request, _('Email relay is not configured properly.' ' Newsletter cannot be sent.')) return redirect(reverse('newsletter.detail.view', kwargs={'pk': newsletter.pk})) return super(NewsletterResendView, self).dispatch(request, *args, **kwargs)
def dispatch(self, request, *args, **kwargs): pk = int(kwargs.get('pk')) newsletter = get_object_or_404(Newsletter, pk=pk) if newsletter.send_status == 'draft': return redirect( reverse('newsletter.action.step4', kwargs={'pk': newsletter.pk})) elif newsletter.send_status == 'sending' or newsletter.send_status == 'resending': return redirect( reverse('newsletter.detail.view', kwargs={'pk': newsletter.pk})) if not is_newsletter_relay_set(): messages.error( request, _('Email relay is not configured properly.' ' Newsletter cannot be sent.')) return redirect( reverse('newsletter.detail.view', kwargs={'pk': newsletter.pk})) return super(NewsletterResendView, self).dispatch(request, *args, **kwargs)
def email_chapter_members(email, chapter_memberships, **kwargs): """ Email to pending members or corporate members. """ site_url = get_setting('site', 'global', 'siteurl') site_display_name = get_setting('site', 'global', 'sitedisplayname') tmp_body = email.body # if possible, use the email backend set up for newsletters if is_newsletter_relay_set(): connection = get_newsletter_connection() else: connection = None request = kwargs.get('request') total_sent = 0 subject = email.subject msg = '<div class="hide" id="m-streaming-content" style="margin: 2em 5em;text-align: left; line-height: 1.3em;">' msg += '<h1>Processing ...</h1>' for member in chapter_memberships: first_name = member.user.first_name last_name = member.user.last_name email.recipient = member.user.email if email.recipient: view_url = '{0}{1}'.format( site_url, reverse('chapters.membership_details', args=[member.id])) edit_url = '{0}{1}'.format( site_url, reverse('chapters.membership_edit', args=[member.id])) template = Template(email.body) context = Context({ 'site_url': site_url, 'site_display_name': site_display_name, "first_name": first_name, 'last_name': last_name, 'view_url': view_url, 'edit_url': edit_url, 'chapter_name': member.chapter.title }) email.body = template.render(context) # replace relative to absolute urls email.body = email.body.replace("src=\"/", f"src=\"{site_url}/") email.body = email.body.replace("href=\"/", f"href=\"{site_url}/") email.send(connection) total_sent += 1 msg += f'{total_sent}. Email sent to {first_name} {last_name} {email.recipient}<br />' if total_sent % 10 == 0: yield msg msg = '' email.body = tmp_body # restore to the original request.session['email_subject'] = email.subject request.session['email_body'] = email.body dest = _('Chapter members') opts = {} opts['summary'] = '<font face=""Arial"" color=""#000000"">' opts['summary'] += 'Emails sent to {0} ({1})</font><br><br>'.format( dest, total_sent) opts['summary'] += '<font face=""Arial"" color=""#000000"">' opts['summary'] += 'Email Sent Appears Below in Raw Format' opts['summary'] += '</font><br><br>' opts['summary'] += email.body # send summary email.subject = 'SUMMARY: %s' % email.subject email.body = opts['summary'] email.recipient = request.user.email email.send(connection) msg += f'DONE!<br /><br />Successfully sent email "{subject}" to <strong>{total_sent}</strong> pending members.' msg += '</div>' yield msg template_name = 'chapters/memberships/message/email-chapter-members-conf.html' template = get_template(template_name) context = { 'total_sent': total_sent, 'chapter_memberships': chapter_memberships } rendered = template.render(context=context, request=request) rendered = _strip_content_above_doctype(rendered) yield rendered