def notify_event_creation(event, occurrences=None): """Send email notifications when a new Event is created :param event: The `Event` that has been created. :param occurrences: A list of event occurrences in case of a series of events. If specified, the links and dates/times are only taken from the events in this list. """ emails = set() query = (event.category.chain_query. filter(Category.notify_managers | (Category.event_creation_notification_emails != [])) .options(joinedload('acl_entries'))) for cat in query: emails.update(cat.event_creation_notification_emails) if cat.notify_managers: for manager in cat.get_manager_list(): if manager.is_single_person: emails.add(manager.email) elif manager.is_group: emails.update(x.email for x in manager.get_members()) if emails: template = get_template_module('events/emails/event_creation.txt', event=event, occurrences=occurrences) send_email(make_email(bcc_list=emails, template=template))
def _send(action, user, plugin, event, room, template_module): to_list = {user.email} cc_list = plugin.get_notification_cc_list(action, room, event) - to_list bcc_list = plugin.get_notification_bcc_list(action, room, event) - cc_list - to_list email = make_email(to_list, cc_list, bcc_list, template=template_module, html=True) send_email(email, event, plugin.friendly_name)
def compose_email_to_manager(self, **mail_params): room = self.reservation.room to_list = {room.owner.email } | room.manager_emails | room.notification_emails subject = self._get_email_subject(**mail_params) body = self._make_body(mail_params, reservation=self.reservation) return make_email(to_list=to_list, subject=subject, body=body)
def send_abstract_notifications(abstract): """Send abstract notification e-mails. :param abstract: the abstract that is going to be checked against the event's notification rules :return: whether an email has been sent """ sent = False for email_tpl in abstract.event.abstract_email_templates: matched = False for rule in email_tpl.rules: if check_rule('abstract-notifications', rule, abstract=abstract, event=abstract.event): matched = True to_recipients = [] if email_tpl.include_submitter: to_recipients.append(abstract.submitter.email) if email_tpl.include_authors: to_recipients += [author.email for author in abstract.primary_authors] cc_recipients = list(email_tpl.extra_cc_emails) if email_tpl.include_coauthors: cc_recipients += [author.email for author in abstract.secondary_authors] tpl = get_abstract_notification_tpl_module(email_tpl, abstract) email = make_email(to_list=to_recipients, cc_list=cc_recipients, reply_address=email_tpl.reply_to_address, template=tpl) send_email(email, abstract.event, 'Abstracts', session.user) abstract.email_logs.append(AbstractEmailLogEntry.create_from_email(email, email_tpl=email_tpl, user=session.user)) sent = True if email_tpl.stop_on_match and matched: break return sent
def _notify_registration(registration, template, to_managers=False): from fossir.modules.events.registration.util import get_ticket_attachments attachments = None regform = registration.registration_form tickets_handled = values_from_signal( signals.event.is_ticketing_handled.send(regform), single_value=True) if (not to_managers and regform.tickets_enabled and regform.ticket_on_email and not any(tickets_handled) and registration.state == RegistrationState.complete): attachments = get_ticket_attachments(registration) template = get_template_module( 'events/registration/emails/{}'.format(template), registration=registration) to_list = registration.email if not to_managers else registration.registration_form.manager_notification_recipients from_address = registration.registration_form.sender_address if not to_managers else None mail = make_email(to_list=to_list, template=template, html=True, from_address=from_address, attachments=attachments) send_email(mail, event=registration.registration_form.event, module='Registration', user=session.user)
def _process(self): db.session.delete(self.request) tpl = get_template_module( 'users/emails/registration_request_rejected.txt', req=self.request) send_email(make_email(self.request.email, template=tpl)) flash(_('The request has been rejected.'), 'success') return jsonify_data()
def _registered(user, identity, from_moderation, **kwargs): from fossir.modules.users.util import get_admin_emails if (from_moderation or identity is None or identity.provider != 'fossir' or not user_management_settings.get('notify_account_creation')): return tpl = get_template_module('users/emails/profile_registered_admins.txt', user=user) send_email(make_email(get_admin_emails(), template=tpl))
def compose_email_to_user(self, **mail_params): creator = self.reservation.created_by_user to_list = {creator.email} if self.reservation.contact_email: to_list.add(self.reservation.contact_email) subject = self._get_email_subject(**mail_params) body = self._make_body(mail_params, reservation=self.reservation) return make_email(to_list=to_list, subject=subject, body=body)
def notify_static_site_success(static_site): template = get_template_module( 'events/static/emails/download_notification_email.txt', user=static_site.creator, event=static_site.event, link=url_for('static_site.download', static_site, _external=True)) return make_email({static_site.creator.email}, template=template, html=False)
def compose_email_to_vc_support(self, **mail_params): from fossir.modules.rb import rb_settings if self.reservation.is_accepted and self.reservation.uses_vc: to_list = rb_settings.get('vc_support_emails') if to_list: subject = self._get_email_subject(**mail_params) body = self._make_body(mail_params, reservation=self.reservation) return make_email(to_list=to_list, subject=subject, body=body)
def send_submission_notification(self, submission): if not self.notifications_enabled: return template_module = get_template_module( 'events/surveys/emails/new_submission_email.txt', submission=submission) email = make_email(bcc_list=self.new_submission_emails, template=template_module) send_email(email, event=self.event, module='Surveys') logger.info('Sending submission notification for survey %s', self)
def _send_confirmation(email, salt, endpoint, template, template_args=None, url_args=None, data=None): template_args = template_args or {} url_args = url_args or {} token = secure_serializer.dumps(data or email, salt=salt) url = url_for(endpoint, token=token, _external=True, **url_args) template_module = get_template_module(template, email=email, url=url, **template_args) send_email(make_email(email, template=template_module)) flash(_('We have sent you a verification email. Please check your mailbox within the next hour and open ' 'the link in that email.')) return redirect(url_for(endpoint, **url_args))
def _process(self): user, identity = register_user(self.request.email, self.request.extra_emails, self.request.user_data, self.request.identity_data, self.request.settings) tpl = get_template_module( 'users/emails/registration_request_accepted.txt', user=user) send_email(make_email(self.request.email, template=tpl)) flash(_('The request has been approved.'), 'success') return jsonify_data()
def notify_agreement_new(agreement, email_body=None, cc_addresses=None, from_address=None): template = make_email_template( 'events/agreements/emails/agreement_new.html', agreement, email_body) return make_email(agreement.person_email, cc_list=cc_addresses, from_address=from_address, template=template, html=True)
def send_start_notification(self): if not self.notifications_enabled or self.start_notification_sent or not self.event.has_feature( 'surveys'): return template_module = get_template_module( 'events/surveys/emails/start_notification_email.txt', survey=self) email = make_email(bcc_list=self.start_notification_recipients, template=template_module) send_email(email, event=self.event, module='Surveys') logger.info('Sending start notification for survey %s', self) self.start_notification_sent = True
def _send_confirmation(self, email): token_storage = GenericCache('confirm-email') data = {'email': email, 'user_id': self.user.id} token = make_unique_token(lambda t: not token_storage.get(t)) token_storage.set(token, data, 24 * 3600) send_email( make_email(email, template=get_template_module( 'users/emails/verify_email.txt', user=self.user, email=email, token=token)))
def notify_request(owner, blocking, blocked_rooms): """ Notifies room owner about blockings he has to approve. Expects only blockings for rooms owned by the specified owner """ subject = 'Confirm room blockings' body = render_template( 'rb/emails/blockings/awaiting_confirmation_email_to_manager.txt', owner=owner, blocking=blocking, blocked_rooms=blocked_rooms) return make_email(owner.email, subject=subject, body=body)
def notify_request_response(blocked_room): """ Notifies blocking creator about approval/rejection of his blocking request for a room """ to = blocked_room.blocking.created_by_user.email verb = blocked_room.State(blocked_room.state).title.upper() subject = 'Room blocking {}'.format(verb) body = render_template('rb/emails/blockings/state_email_to_user.txt', blocking=blocked_room.blocking, blocked_room=blocked_room, verb=verb) return make_email(to, subject=subject, body=body)
def _send_emails(self, form, recipients): for recipient in recipients: if self.no_account and isinstance(recipient, EventPerson): recipient.invited_dt = now_utc() email_body = replace_placeholders('event-persons-email', form.body.data, person=recipient, event=self.event, register_link=self.no_account) email_subject = replace_placeholders('event-persons-email', form.subject.data, person=recipient, event=self.event, register_link=self.no_account) tpl = get_template_module('emails/custom.html', subject=email_subject, body=email_body) bcc = [session.user.email] if form.copy_for_sender.data else [] email = make_email(to_list=recipient.email, bcc_list=bcc, from_address=form.from_address.data, template=tpl, html=True) send_email(email, self.event, 'Event Persons')
def _send_email(self, email, comment): # using reply-to for the user email would be nicer, but email clients # usually only show the from address and it's nice to immediately see # whether an error report has an email address associated and if # multiple reports came from the same person template = get_template_module('core/emails/error_report.txt', comment=comment, error_data=self.error_data, server_name=url_parse( config.BASE_URL).netloc) send_email( make_email(config.SUPPORT_EMAIL, from_address=(email or config.NO_REPLY_EMAIL), template=template))
def compose_email_to_assistance(self, **mail_params): from fossir.modules.rb import rb_settings if self.reservation.room.notification_for_assistance: if self.reservation.needs_assistance or mail_params.get( 'assistance_cancelled'): to_list = rb_settings.get('assistance_emails') if to_list: subject = self._get_email_subject(**mail_params) body = self._make_body(mail_params, reservation=self.reservation) return make_email(to_list=to_list, subject=subject, body=body)
def send(self): """Sends the reminder to its recipients.""" self.is_sent = True recipients = self.all_recipients if not recipients: logger.info( 'Notification %s has no recipients; not sending anything', self) return email_tpl = make_reminder_email(self.event, self.include_summary, self.message) email = make_email(bcc_list=recipients, from_address=self.reply_to_address, template=email_tpl) send_email(email, self.event, 'Reminder', self.creator)
def notify_event_managers(req, template, **context): """Notifies event managers about something :param req: the :class:`Request` :param template: the template for the notification :param context: data passed to the template """ event = req.event from_addr = config.SUPPORT_EMAIL context['event'] = event context['req'] = req tpl_event_managers = _get_template_module(template, **context) return make_email(event.all_manager_emails, from_address=from_addr, subject=tpl_event_managers.get_subject(), body=tpl_event_managers.get_body())
def _send_emails(self, form): for registration in self.registrations: email_body = replace_placeholders('registration-email', form.body.data, regform=self.regform, registration=registration) email_subject = replace_placeholders('registration-email', form.subject.data, regform=self.regform, registration=registration) template = get_template_module('events/registration/emails/custom_email.html', email_subject=email_subject, email_body=email_body) bcc = [session.user.email] if form.copy_for_sender.data else [] attachments = (get_ticket_attachments(registration) if 'attach_ticket' in form and form.attach_ticket.data else None) email = make_email(to_list=registration.email, cc_list=form.cc_addresses.data, bcc_list=bcc, from_address=form.from_address.data, template=template, html=True, attachments=attachments) send_email(email, self.event, 'Registration')
def notify_invitation(invitation, email_subject, email_body, from_address): """Send a notification about a new registration invitation.""" email_body = replace_placeholders('registration-invitation-email', email_body, invitation=invitation) email_subject = replace_placeholders('registration-invitation-email', email_subject, invitation=invitation) template = get_template_module('emails/custom.html', subject=email_subject, body=email_body) email = make_email(invitation.email, from_address=from_address, template=template, html=True) send_email(email, invitation.registration_form.event, 'Registration', session.user)
def _send_emails(self, form, recipients): for recipient in recipients: email_body = replace_placeholders('survey-link-email', form.body.data, event=self.event, survey=self.survey) email_subject = replace_placeholders('survey-link-email', form.subject.data, event=self.event, survey=self.survey) tpl = get_template_module('emails/custom.html', subject=email_subject, body=email_body) bcc = [session.user.email] if form.copy_for_sender.data else [] email = make_email(to_list=recipient, bcc_list=bcc, from_address=form.from_address.data, template=tpl, html=True) send_email(email, self.event, 'Surveys')
def notify_upcoming_occurrences(user, occurrences): tpl = get_template_module('rb/emails/reservations/reminders/upcoming_occurrence.html', occurrences=occurrences, user=user) return make_email(to_list={user.email}, template=tpl, html=True)
def notify_new_signature_to_manager(agreement): template = get_template_module( 'events/agreements/emails/new_signature_email_to_manager.txt', agreement=agreement) return make_email(agreement.event.all_manager_emails, template=template)
def _registration_requested(req, **kwargs): from fossir.modules.users.util import get_admin_emails tpl = get_template_module('users/emails/profile_requested_admins.txt', req=req) send_email(make_email(get_admin_emails(), template=tpl))
def notify_amount_inconsistency(registration, amount, currency): event = registration.registration_form.event to = event.creator.email body = render_template('events/payment/emails/payment_inconsistency_email_to_manager.txt', event=event, registration=registration, amount=amount, currency=currency) return make_email(to, subject='Payment inconsistency', body=body)