def form_valid(self, form): site = Site.objects.get_current() data = {'naam': self.request.user.profiel.naam_volledig} data.update(app_settings()) body = render_to_string('email/gebruiker_uitnodigen.txt', context=data, request=self.request) body_html = render_to_string('email/gebruiker_uitnodigen.html', data) subject = 'VraagMij uitnodiging' mail = Mail( from_email=('noreply@%s' % site.domain, 'VraagMij'), to_emails=(form.cleaned_data.get('email'), self.request.user.profiel.naam_volledig), subject=subject, plain_text_content=body, html_content=body_html, ) if settings.ENV != 'develop': try: sg = sendgrid.SendGridAPIClient(settings.SENDGRID_API_KEY) response = sg.send(mail) print(response.status_code) print(response.body) print(response.headers) except Exception as e: print(e.message) else: print(body) return super().form_valid(form)
def password_reset_new_user(request, flow): from .context_processors import app_settings data = { 'template_name': 'registration/reset_password.html', 'password_reset_form': MailAPIPasswordResetForm, 'email_template_name': 'registration/password_reset_email_%s.html' % flow, 'post_reset_redirect': reverse_lazy('herstel_wachtwoord_klaar'), 'subject_template_name': 'registration/password_reset_subject.txt', 'extra_email_context': app_settings(), } if flow == 'new': data.update({ 'extra_context': { 'email': request.GET.get('email'), 'flow': flow, }, 'post_reset_redirect': reverse_lazy('wachtwoord_instellen_klaar'), 'subject_template_name': 'registration/password_reset_subject_new.txt', }) response = auth_views.password_reset(request, **data) return response
def handle(self, *args, **options): now = datetime.datetime.now(tzlocal()) if get_container_id() != cache.get(get_cronjob_worker_cache_key()): raise CommandError("You're not the worker!") print('%s: %s' % (now.strftime('%Y-%m-%d %H:%M'), self.__module__.split('.')[-1])) site = Site.objects.get_current() if site.instelling: sg = sendgrid.SendGridAPIClient(apikey=settings.SENDGRID_API_KEY) subject = 'VraagMij - Is je profiel up-to-date?' for u in get_users(): if u.profiel.hou_me_op_de_hoogte_mail: o = { 'naam': u.profiel.naam_volledig, 'profiel': u.profiel, } o.update(app_settings()) body = render_to_string( 'email/mail_account_active_check.txt', o) body_html = render_to_string( 'email/mail_account_active_check.html', o) mail = Mail(Email('noreply@%s' % site.domain), subject, Email(u.email), Content("text/plain", body)) mail.add_content(Content("text/html", body_html)) if settings.ENV != 'develop': sg.client.mail.send.post(request_body=mail.get()) print('Send mail to: %s' % u.email) else: print(body)
def get_context_data(self, **kwargs): from jeugdzorg.context_processors import app_settings context = {} context.update(app_settings()) data = super().get_context_data(**kwargs) django_engine = engines['django'] template = django_engine.from_string(self.object.inhoud) data['inhoud'] = template.render(context) return data
def form_valid(self, form): site = Site.objects.get_current() sg = sendgrid.SendGridAPIClient(apikey=settings.SENDGRID_API_KEY) data = {'naam': self.request.user.profiel.naam_volledig} data.update(app_settings()) body = render_to_string('email/gebruiker_uitnodigen.txt', context=data, request=self.request) body_html = render_to_string('email/gebruiker_uitnodigen.html', data) subject = 'VraagMij uitnodiging' mail = Mail(Email('noreply@%s' % site.domain), subject, Email(form.cleaned_data.get('email')), Content("text/plain", body)) mail.add_content(Content("text/html", body_html)) if settings.ENV != 'develop': sg.client.mail.send.post(request_body=mail.get()) else: print(body) return super().form_valid(form)
def handle(self, *args, **options): now = datetime.datetime.now(tzlocal()) if get_container_id() != cache.get(get_cronjob_worker_cache_key()): raise CommandError("You're not the worker!") print('%s: %s' % (now.strftime('%Y-%m-%d %H:%M'), self.__module__.split('.')[-1])) site = Site.objects.get_current() if site.instelling: sg = sendgrid.SendGridAPIClient(apikey=settings.SENDGRID_API_KEY) now = now + dateutil.relativedelta.relativedelta(months=-1) regeling_nieuw = Regeling.objects.filter( **{'datum_gecreeerd__gt': now}) gebruikers_nieuw = User.objects.filter(**{ 'date_joined__gt': now, }).exclude(profiel=None) regeling_gewijzigd = Regeling.objects.filter( **{ 'datum_gecreeerd__lte': now, 'datum_opgeslagen__gt': now, }) regeling_nieuw_str = [[ r.titel, 'https://%s%s' % (site.domain, reverse('detail_regeling', kwargs={'pk': r.id})) ] for r in regeling_nieuw] regeling_gewijzigd_str = [[ r.titel, 'https://%s%s' % (site.domain, reverse('detail_regeling', kwargs={'pk': r.id})) ] for r in regeling_gewijzigd] gebruikers_nieuw_str = [[ r.profiel.naam_volledig, 'https://%s%s' % (site.domain, reverse('detail_contact', kwargs={'pk': r.id})) ] for r in gebruikers_nieuw] django_engine = engines['django'] maand = maanden[int(now.strftime('%-m')) - 1] subject = 'VraagMij - updates maand %s' % maand data = { 'regeling_nieuw': regeling_nieuw_str, 'regeling_gewijzigd': regeling_gewijzigd_str, 'gebruikers_nieuw': gebruikers_nieuw_str, 'subject': subject, } for u in User.objects.exclude(profiel=None): if u.profiel.hou_me_op_de_hoogte_mail: o = { 'naam': u.profiel.naam_volledig, 'profiel': u.profiel, } o.update(data) o.update(app_settings()) template = django_engine.from_string( site.instelling.update_mail_content) template_html = django_engine.from_string( site.instelling.update_mail_content_html) o.update({ 'content': template_html.render(o), }) body_html = render_to_string('email/update_mail.html', o) body = template.render(o) mail_settings = MailSettings() mail = Mail(Email('noreply@%s' % site.domain), subject, Email(u.email), Content("text/plain", body)) mail.mail_settings = mail_settings mail.add_content(Content("text/html", body_html)) # # mail.add_attachment(build_logo()) # h1 = Header('Content-Id', '<gfgrtdtrdk9769875786thgjhbj>') # mail.add_header(h1) if settings.ENV != 'develop': sg.client.mail.send.post(request_body=mail.get()) # print('Send mail to: %s' % u.email) else: print(body_html)
def handle(self, *args, **options): now = datetime.datetime.now(tzlocal()) if get_container_id() != cache.get(get_cronjob_worker_cache_key()): raise CommandError("You're not the worker!") print('%s: %s' % (now.strftime('%Y-%m-%d %H:%M'), self.__module__.split('.')[-1])) site = Site.objects.get_current() if site.instelling: sg = sendgrid.SendGridAPIClient(settings.SENDGRID_API_KEY) now = now + dateutil.relativedelta.relativedelta(months=-1) regeling_nieuw = Regeling.objects.filter( **{'datum_gecreeerd__gt': now}) gebruikers_nieuw = User.objects.filter(**{ 'date_joined__gt': now, }).exclude(profiel=None) regeling_gewijzigd = Regeling.objects.filter( **{ 'datum_gecreeerd__lte': now, 'datum_opgeslagen__gt': now, }) regeling_nieuw_str = [[ r.titel, 'https://%s%s' % (site.domain, reverse('detail_regeling', kwargs={'pk': r.id})) ] for r in regeling_nieuw] regeling_gewijzigd_str = [[ r.titel, 'https://%s%s' % (site.domain, reverse('detail_regeling', kwargs={'pk': r.id})) ] for r in regeling_gewijzigd] gebruikers_nieuw_str = [[ r.profiel.naam_volledig, 'https://%s%s' % (site.domain, reverse('detail_contact', kwargs={'pk': r.id})) ] for r in gebruikers_nieuw] django_engine = engines['django'] maand = maanden[int(now.strftime('%-m')) - 1] subject = 'VraagMij - updates maand %s' % maand data = { 'regeling_nieuw': regeling_nieuw_str, 'regeling_gewijzigd': regeling_gewijzigd_str, 'gebruikers_nieuw': gebruikers_nieuw_str, 'subject': subject, } for u in User.objects.exclude(profiel=None): if u.profiel.hou_me_op_de_hoogte_mail: o = { 'naam': u.profiel.naam_volledig, 'profiel': u.profiel, } o.update(data) o.update(app_settings()) template = django_engine.from_string( site.instelling.update_mail_content) template_html = django_engine.from_string( site.instelling.update_mail_content_html) o.update({ 'content': template_html.render(o), }) body_html = render_to_string('email/update_mail.html', o) body = template.render(o) mail_settings = MailSettings() mail = Mail( from_email=('noreply@%s' % site.domain, 'VraagMij'), to_emails=(u.email, u.profiel.naam_volledig), subject=subject, plain_text_content=body, html_content=body_html, ) mail.mail_settings = mail_settings if settings.ENV != 'develop': try: response = sg.send(mail) print(response.status_code) print(response.body) print(response.headers) except Exception as e: print(e.message) else: print(body_html)