def send_booking_recap_emails(booking: Booking) -> None: recipients = [settings.ADMINISTRATION_EMAIL_ADDRESS] booking_email = booking.stock.offer.bookingEmail if booking_email: recipients.append(booking_email) data = retrieve_data_for_offerer_booking_recap_email(booking) mails.send(recipients=recipients, data=data)
def send_offerer_driven_cancellation_email_to_offerer( booking: Booking) -> None: offerer_email = booking.stock.offer.bookingEmail recipients = [] if offerer_email: recipients.append(offerer_email) recipients.append(settings.ADMINISTRATION_EMAIL_ADDRESS) email = make_offerer_driven_cancellation_email_for_offerer(booking) mails.send(recipients=recipients, data=email)
def send_rejection_email_to_beneficiary_pre_subscription( beneficiary_pre_subscription: BeneficiaryPreSubscription, beneficiary_is_eligible: bool, ) -> None: if not beneficiary_is_eligible: data = make_not_eligible_beneficiary_pre_subscription_rejected_data() else: data = make_duplicate_beneficiary_pre_subscription_rejected_data() mails.send(recipients=[beneficiary_pre_subscription.email], data=data)
def send_offer_validation_status_update_email( offer: Offer, validation_status: OfferValidationStatus, recipient_emails: list[str] ) -> bool: if validation_status is OfferValidationStatus.APPROVED: offer_data = retrieve_data_for_offer_approval_email(offer) return mails.send(recipients=recipient_emails, data=offer_data) if validation_status is OfferValidationStatus.REJECTED: offer_data = retrieve_data_for_offer_rejection_email(offer) return mails.send(recipients=recipient_emails, data=offer_data) return False
def send_expired_bookings_recap_email_to_beneficiary(beneficiary: User, bookings: list[Booking]) -> None: books_bookings, other_bookings = filter_books_bookings(bookings) if books_bookings: books_bookings_data = build_expired_bookings_recap_email_data_for_beneficiary( beneficiary, bookings, booking_constants.BOOKS_BOOKINGS_AUTO_EXPIRY_DELAY.days ) mails.send(recipients=[beneficiary.email], data=books_bookings_data) if other_bookings: other_bookings_data = build_expired_bookings_recap_email_data_for_beneficiary( beneficiary, bookings, booking_constants.BOOKINGS_AUTO_EXPIRY_DELAY.days ) mails.send(recipients=[beneficiary.email], data=other_bookings_data)
def send_report_notification(user: User, offer: Offer, reason: str, custom_reason: Optional[str]) -> bool: data = build_offer_report_data(user, offer, reason, custom_reason) recipients = [settings.REPORT_OFFER_EMAIL_ADDRESS] if reason == Reason.OTHER.value: recipients = [settings.SUPPORT_EMAIL_ADDRESS] return mails.send(recipients=recipients, data=data)
def maybe_send_offerer_validation_email(offerer: Offerer, user_offerer: UserOfferer) -> bool: if offerer.isValidated and user_offerer.isValidated: return None email = make_validation_email_object(offerer, user_offerer) recipients = [settings.ADMINISTRATION_EMAIL_ADDRESS] return mails.send(recipients=recipients, data=email)
def send_expired_individual_bookings_recap_email_to_offerer(offerer: Offerer, bookings: list[Booking]) -> None: offerer_booking_email = bookings[0].stock.offer.bookingEmail if offerer_booking_email: books_bookings, other_bookings = filter_books_bookings(bookings) if books_bookings: books_bookings_data = build_expired_bookings_recap_email_data_for_offerer( offerer, books_bookings, booking_constants.BOOKS_BOOKINGS_AUTO_EXPIRY_DELAY.days ) mails.send(recipients=[offerer_booking_email], data=books_bookings_data) if other_bookings: other_bookings_data = build_expired_bookings_recap_email_data_for_offerer( offerer, other_bookings, booking_constants.BOOKINGS_AUTO_EXPIRY_DELAY.days ) mails.send(recipients=[offerer_booking_email], data=other_bookings_data)
def send_confirmation_email_change_email(user: User, new_email: str, confirmation_link: str) -> bool: data = get_confirmation_email_change_data(user.firstName, confirmation_link) return mails.send(recipients=[new_email], data=data, send_with_sendinblue=True)
def test_send_with_mailjet(self): expected = copy.deepcopy(self.expected_sent_data) expected["MJ-TemplateErrorReporting"] = "*****@*****.**" with requests_mock.Mocker() as mock: posted = mock.post("https://api.eu.mailjet.com/v3/send") successful = mails.send(recipients=self.recipients, data=self.data) assert posted.last_request.json() == expected assert successful
def send_reset_password_email_to_native_app_user( user_email: str, token_value: str, expiration_date: datetime, ) -> bool: data = retrieve_data_for_reset_password_native_app_email( user_email, token_value, expiration_date) return mails.send(recipients=[user_email], data=data)
def send_payments_report_emails( not_processable_payments_csv: str, error_payments_csv: str, grouped_payments: Dict, recipients: List[str], ) -> bool: email = make_payments_report_email(not_processable_payments_csv, error_payments_csv, grouped_payments) return mails.send(recipients=recipients, data=email)
def send_payments_report_emails( not_processable_payments_csv: str, n_payments_by_status: dict, recipients: list[str], ) -> bool: email = make_payments_report_email( not_processable_payments_csv, n_payments_by_status, ) return mails.send(recipients=recipients, data=email)
def send_user_emails_for_email_change(user: User, new_email: str) -> None: user_with_new_email = User.query.filter_by(email=new_email).first() if user_with_new_email: return information_data = build_beneficiary_information_email_change_data(user.firstName) information_sucessfully_sent = mails.send(recipients=[user.email], data=information_data) if not information_sucessfully_sent: raise MailServiceException() link_for_email_change = _build_link_for_email_change(user.email, new_email) confirmation_data = build_beneficiary_confirmation_email_change_data( user.firstName, link_for_email_change, ) confirmation_sucessfully_sent = mails.send(recipients=[new_email], data=confirmation_data) if not confirmation_sucessfully_sent: raise MailServiceException() return
def send_activation_email( user: User, native_version: bool = False, token: users_models.Token = None, ) -> bool: if not native_version: data = beneficiary_activation.get_activation_email_data(user=user) else: data = beneficiary_activation.get_activation_email_data_for_native( user=user, token=token) return mails.send(recipients=[user.email], data=data)
def confirm_educational_booking( educational_booking_id: int) -> EducationalBooking: educational_booking = educational_repository.find_educational_booking_by_id( educational_booking_id) if educational_booking is None: raise exceptions.EducationalBookingNotFound() booking: bookings_models.Booking = educational_booking.booking if booking.status == bookings_models.BookingStatus.CONFIRMED: return educational_booking validation.check_educational_booking_status(educational_booking) validation.check_confirmation_limit_date_has_not_passed( educational_booking) educational_institution_id = educational_booking.educationalInstitutionId educational_year_id = educational_booking.educationalYearId with transaction(): deposit = educational_repository.get_and_lock_educational_deposit( educational_institution_id, educational_year_id) validation.check_institution_fund( educational_institution_id, educational_year_id, booking.total_amount, deposit, ) booking.mark_as_confirmed() repository.save(booking) logger.info( "Head of institution confirmed an educational offer", extra={ "bookingId": booking.id, }, ) if booking.stock.offer.bookingEmail: mails.send(recipients=[booking.stock.offer.bookingEmail], data=_build_booking_confirmation_mail_data(booking)) return educational_booking
def send_accepted_as_beneficiary_email(user: User) -> bool: if UserRole.UNDERAGE_BENEFICIARY in user.roles: data = get_accepted_as_underage_beneficiary_email_data(user) elif UserRole.BENEFICIARY in user.roles: data = get_accepted_as_beneficiary_email_data(user) else: data = None if not data: return False return mails.send(recipients=[user.email], data=data, send_with_sendinblue=True)
def send_soon_to_be_expired_individual_bookings_recap_email_to_beneficiary( beneficiary: User, bookings: list[Booking] ) -> None: books_bookings, other_bookings = filter_books_bookings(bookings) if books_bookings: books_bookings_data = build_soon_to_be_expired_bookings_recap_email_data_for_beneficiary( beneficiary=beneficiary, bookings=books_bookings, days_before_cancel=booking_constants.BOOKS_BOOKINGS_EXPIRY_NOTIFICATION_DELAY.days, days_from_booking=booking_constants.BOOKS_BOOKINGS_AUTO_EXPIRY_DELAY.days - booking_constants.BOOKS_BOOKINGS_EXPIRY_NOTIFICATION_DELAY.days, ) mails.send(recipients=[beneficiary.email], data=books_bookings_data) if other_bookings: other_bookings_data = build_soon_to_be_expired_bookings_recap_email_data_for_beneficiary( beneficiary=beneficiary, bookings=other_bookings, days_before_cancel=booking_constants.BOOKINGS_EXPIRY_NOTIFICATION_DELAY.days, days_from_booking=booking_constants.BOOKINGS_AUTO_EXPIRY_DELAY.days - booking_constants.BOOKINGS_EXPIRY_NOTIFICATION_DELAY.days, ) mails.send(recipients=[beneficiary.email], data=other_bookings_data)
def send_transactional_sms(self, recipient: str, content: str) -> bool: if recipient in settings.WHITELISTED_SMS_RECIPIENTS: if not super().send_transactional_sms(recipient, content): return False mail_content = { "Subject": "Code de validation du téléphone", "Html-part": (f"<div>Le contenu suivant serait envoyé par sms au numéro {recipient}</div>" f"<div>{content}</div></div>"), } return mails.send(recipients=[settings.DEV_EMAIL_ADDRESS], data=mail_content)
def test_send_failure(self): successful = mails.send(recipients=self.recipients, data=self.data) assert not successful email = Email.query.one() assert email.status == EmailStatus.ERROR assert email.content == self.expected_sent_data
def send_validation_confirmation_email_to_pro(offerer: Offerer) -> None: offerer_email = find_new_offerer_user_email(offerer.id) data = retrieve_data_for_new_offerer_validation_email(offerer) mails.send(recipients=[offerer_email], data=data)
def send_attachment_validation_email_to_pro_offerer(user_offerer: UserOfferer) -> None: data = retrieve_data_for_offerer_attachment_validation_email(user_offerer.offerer) mails.send(recipients=[user_offerer.user.email], data=data)
def send_offer_creation_notification_to_administration(offer: Offer, author: User) -> bool: email = make_offer_creation_notification_email(offer, author) return mails.send(recipients=[settings.ADMINISTRATION_EMAIL_ADDRESS], data=email)
def send_payment_details_email(csv_attachment: str, recipients: List[str]) -> bool: email = make_payment_details_email(csv_attachment) return mails.send(recipients=recipients, data=email)
def send_wallet_balances_email(csv_attachment: str, recipients: List[str]) -> bool: email = make_wallet_balances_email(csv_attachment) return mails.send(recipients=recipients, data=email)
def send_payment_message_email(xml_attachment: str, checksum: bytes, recipients: List[str]) -> bool: email = make_payment_message_email(xml_attachment, checksum) return mails.send(recipients=recipients, data=email)
def send_user_driven_cancellation_email_to_offerer(booking: Booking) -> None: offerer_booking_email = booking.stock.offer.bookingEmail if offerer_booking_email: data = retrieve_offerer_booking_recap_email_data_after_user_cancellation(booking) mails.send(recipients=[offerer_booking_email], data=data)
def send_email_confirmation_email(user: User, token: Token) -> bool: data = get_email_confirmation_email_data(user=user, token=token) return mails.send(recipients=[user.email], data=data, send_with_sendinblue=True)
def send_warning_to_user_after_pro_booking_cancellation(booking: Booking) -> None: data = retrieve_data_to_warn_user_after_pro_booking_cancellation(booking) mails.send(recipients=[booking.email], data=data)
def send_offerer_driven_cancellation_email_to_offerer(booking: Booking) -> None: offerer_booking_email = booking.stock.offer.bookingEmail if offerer_booking_email: email = make_offerer_driven_cancellation_email_for_offerer(booking) mails.send(recipients=[offerer_booking_email], data=email)