def send_signup_email(flow): logger.info(f"Sending signup email to {flow.email=}:") # whether we've sent an email at all yet email_sent_before = flow.email_sent if flow.email_verified: # we just send a link to continue, not a verification link signup_link = urls.signup_link(token=flow.flow_token) elif flow.email_token and flow.token_is_valid: # if the verification email was sent and still is not expired, just resend the verification email signup_link = urls.signup_link(token=flow.email_token) else: # otherwise send a fresh email with new token token = urlsafe_secure_token() flow.email_verified = False flow.email_token = token flow.email_token_expiry = now() + SIGNUP_EMAIL_TOKEN_VALIDITY signup_link = urls.signup_link(token=flow.email_token) flow.email_sent = True logger.info(f"Link is: {signup_link}") template = "signup_verify" if not email_sent_before else "signup_continue" email.enqueue_email_from_template(flow.email, template, template_args={ "flow": flow, "signup_link": signup_link })
def send_reference_reminder_email(user, other_user, host_request, surfed, time_left_text): logger.info( f"Sending host reference email to {user=}, they have {time_left_text} left to write a ref" ) email.enqueue_email_from_template( user.email, "reference_reminder", template_args={ "user": user, "other_user": other_user, "host_request": host_request, "leave_reference_link": urls.leave_reference_link( reference_type="surfed" if surfed else "hosted", to_user_id=other_user.id, host_request_id=host_request.conversation_id, ), "surfed": surfed, "time_left_text": time_left_text, }, )
def send_host_reference_email(reference, both_written): """ both_written == true if both the surfer and hoster wrote a reference """ assert reference.host_request_id logger.info( f"Sending host reference email to {reference.to_user=} for {reference.id=}" ) surfed = reference.host_request.surfer_user_id != reference.from_user_id email.enqueue_email_from_template( reference.to_user.email, "host_reference", template_args={ "reference": reference, "leave_reference_link": urls.leave_reference_link( reference_type="surfed" if surfed else "hosted", to_user_id=reference.from_user_id, host_request_id=reference.host_request.conversation_id, ), # if this reference was written by the surfer, then the recipient hosted "surfed": surfed, "both_written": both_written, }, )
def send_digest_email(notifications: List[Notification]): logger.info(f"Sending digest email to {notification.user=}:") email.enqueue_email_from_template( notification.user.email, "digest", template_args={"notifications": notifications}, )
def process_send_request_notifications(payload): """ Sends out email notifications for unseen messages in host requests (as surfer or host) """ logger.info(f"Sending out email notifications for unseen messages in host requests") with session_scope() as session: # requests where this user is surfing surfing_reqs = session.execute( select(User, HostRequest, func.max(Message.id)) .where(User.is_visible) .join(HostRequest, HostRequest.surfer_user_id == User.id) .join(Message, Message.conversation_id == HostRequest.conversation_id) .where(Message.id > HostRequest.surfer_last_seen_message_id) .where(Message.id > User.last_notified_request_message_id) .where(Message.time < now() - timedelta(minutes=5)) .where(Message.message_type == MessageType.text) .group_by(User, HostRequest) ).all() # where this user is hosting hosting_reqs = session.execute( select(User, HostRequest, func.max(Message.id)) .where(User.is_visible) .join(HostRequest, HostRequest.host_user_id == User.id) .join(Message, Message.conversation_id == HostRequest.conversation_id) .where(Message.id > HostRequest.host_last_seen_message_id) .where(Message.id > User.last_notified_request_message_id) .where(Message.time < now() - timedelta(minutes=5)) .where(Message.message_type == MessageType.text) .group_by(User, HostRequest) ).all() for user, host_request, max_message_id in surfing_reqs: user.last_notified_request_message_id = max(user.last_notified_request_message_id, max_message_id) session.commit() email.enqueue_email_from_template( user.email, "unseen_message_guest", template_args={ "user": user, "host_request": host_request, "host_request_link": urls.host_request_link_guest(), }, ) for user, host_request, max_message_id in hosting_reqs: user.last_notified_request_message_id = max(user.last_notified_request_message_id, max_message_id) session.commit() email.enqueue_email_from_template( user.email, "unseen_message_host", template_args={ "user": user, "host_request": host_request, "host_request_link": urls.host_request_link_host(), }, )
def send_password_changed_email(user): """ Send the user an email saying their password has been changed. """ logger.info(f"Sending password changed (notification) email to {user=}") email.enqueue_email_from_template(user.email, "password_changed", template_args={"user": user})
def send_api_key_email(session, user, token, expiry): logger.info(f"Sending API key email to {user=}:") email.enqueue_email_from_template(user.email, "api_key", template_args={ "user": user, "token": token, "expiry": expiry })
def send_signup_email(email_address, token, expiry_text): logger.info(f"Sending signup email to {email_address=}:") logger.info( f"Token: {token=} ({token.created=}, {token.expiry=}) ({expiry_text=})" ) signup_link = urls.signup_link(signup_token=token.token) logger.info(f"Link is: {signup_link}") email.enqueue_email_from_template( email_address, "signup", template_args={"signup_link": signup_link})
def send_donation_email(user, amount, receipt_url): email.enqueue_email_from_template( user.email, "donation_received", template_args={ "user": user, "amount": amount, "receipt_url": receipt_url }, )
def send_email_changed_notification_email(user): """ Send an email to user's original address notifying that it has been changed """ logger.info( f"Sending email changed (notification) email to {user=} (old email: {user.email=}, new email: {user.new_email=})" ) email.enqueue_email_from_template(user.email, "email_changed_notification", template_args={"user": user})
def send_email_changed_notification_email(user): """ Send the user an email saying their email has changed. Goes to the old address """ logger.info( f"Sending email changed (notification) email to {user=} (old email: {user.email=}, new email: {user.new_email=})" ) email.enqueue_email_from_template(user.email, "email_changed_notification", template_args={"user": user})
def send_account_recovered_email(user): logger.info(f"Sending account recovered successful email to {user=}.") logger.info(f"Email for {user.username=} sent to {user.email}.") email.enqueue_email_from_template( user.email, "account_recovered_successful", template_args={ "user": user, "app_link": urls.app_link() }, )
def send_account_deletion_report_email(reason): target_email = config["REPORTS_EMAIL_RECIPIENT"] logger.info(f"Sending account deletion report email to {target_email=}") email.enqueue_email_from_template( target_email, "account_deletion_report", template_args={ "reason": reason, }, )
def send_onboarding_email(user, email_number): email.enqueue_email_from_template( user.email, f"onboarding{email_number}", template_args={ "user": user, "app_link": urls.app_link(), "profile_link": urls.profile_link(), "edit_profile_link": urls.edit_profile_link(), }, )
def maybe_send_contributor_form_email(form): target_email = config["CONTRIBUTOR_FORM_EMAIL_RECIPIENT"] if form.should_notify: email.enqueue_email_from_template( target_email, "contributor_form", template_args={ "form": form, "user_link": urls.user_link(username=form.user.username) }, )
def send_password_reset_email(user, token, expiry_text): logger.info(f"Sending password reset email to {user=}:") password_reset_link = urls.password_reset_link( password_reset_token=token.token) logger.info(f"Link is: {password_reset_link}") email.enqueue_email_from_template(user.email, "password_reset", template_args={ "user": user, "password_reset_link": password_reset_link })
def send_notification_email(notification: Notification): friend_requests_link = urls.friend_requests_link() logger.info(f"Sending notification email to {notification.user=}:") email.enqueue_email_from_template( notification.user.email, "notification", template_args={ "notification": notification, "unsub_all": generate_mute_all(notification.user_id), "unsub_topic_key": generate_unsub_topic_key(notification), "unsub_topic_action": generate_unsub_topic_action(notification), }, )
def send_login_email(user, token, expiry_text): logger.info(f"Sending login email to {user=}:") logger.info(f"Email for {user.username=} to {user.email=}") logger.info( f"Token: {token=} ({token.created=}, {token.expiry=}) ({expiry_text=})" ) login_link = urls.login_link(login_token=token.token) logger.info(f"Link is: {login_link}") email.enqueue_email_from_template(user.email, "login", template_args={ "user": user, "login_link": login_link })
def send_friend_reference_email(reference): assert not reference.host_request_id logger.info( f"Sending friend reference email to {reference.to_user=} for {reference.id=}" ) email.enqueue_email_from_template( reference.to_user.email, "friend_reference", template_args={ "reference": reference, }, )
def send_account_deletion_successful_email(user, undelete_days): logger.info(f"Sending account deletion successful email to {user=}.") logger.info(f"Email for {user.username=} sent to {user.email}.") undelete_link = urls.recover_account_link( account_undelete_token=user.undelete_token) email.enqueue_email_from_template( user.email, "account_deletion_successful", template_args={ "user": user, "undelete_link": undelete_link, "days": undelete_days }, )
def send_email_changed_confirmation_email(user, token, expiry_text): """ Send the user an email confirming their new email. Goes to the new address """ logger.info( f"Sending email changed (confirmation) email to {user=} (old email: {user.email=}, new email: {user.new_email=})" ) confirmation_link = urls.change_email_link(confirmation_token=token) email.enqueue_email_from_template(user.email, "email_changed_confirmation", template_args={ "user": user, "confirmation_link": confirmation_link })
def send_host_request_cancelled_email_to_host(host_request): logger.info( f"Sending host request cancelled email to host: {host_request.host=}:") logger.info( f"Email for {host_request.host.username=} sent to {host_request.host.email=}" ) email.enqueue_email_from_template( host_request.host.email, "host_request_cancelled_host", template_args={ "host_request": host_request, "host_request_link": urls.host_request_link_host(), }, )
def send_message_received_email(user_recipient): messages_link = urls.messages_link() logger.info(f"Sending message received email to {user_recipient=}:") logger.info( f"Email for {user_recipient.username=} sent to {user_recipient.email=}" ) email.enqueue_email_from_template( user_recipient.email, "message_received", template_args={ "user": user_recipient, "messages_link": messages_link, }, )
def send_new_host_request_email(host_request): logger.info(f"Sending host request email to {host_request.host=}:") logger.info(f"Host request sent by {host_request.surfer}") logger.info( f"Email for {host_request.host.username=} sent to {host_request.host.email=}" ) email.enqueue_email_from_template( host_request.host.email, "host_request", template_args={ "host_request": host_request, "host_request_link": urls.host_request_link_host(), }, )
def send_content_report_email(content_report): target_email = config["REPORTS_EMAIL_RECIPIENT"] logger.info(f"Sending content report email to {target_email=}") email.enqueue_email_from_template( target_email, "content_report", template_args={ "report": content_report, "author_user_user_link": urls.user_link(username=content_report.author_user.username), "reporting_user_user_link": urls.user_link(username=content_report.reporting_user.username), }, )
def send_host_request_rejected_email_to_guest(host_request): logger.info( f"Sending host request rejected email to guest: {host_request.surfer=}:" ) logger.info( f"Email for {host_request.surfer.username=} sent to {host_request.surfer.email=}" ) email.enqueue_email_from_template( host_request.surfer.email, "host_request_rejected_guest", template_args={ "host_request": host_request, "host_request_link": urls.host_request_link_guest(), }, )
def send_host_request_email(host_request): host_request_link = urls.host_request_link() logger.info(f"Sending host request email to {host_request.to_user=}:") logger.info(f"Host request sent by {host_request.from_user}") logger.info( f"Email for {host_request.to_user.username=} sent to {host_request.to_user.email=}" ) email.enqueue_email_from_template( host_request.to_user.email, "host_request", template_args={ "host_request": host_request, "host_request_link": host_request_link, }, )
def maybe_send_reference_report_email(reference): target_email = config["REPORTS_EMAIL_RECIPIENT"] if reference.should_report: logger.info(f"Sending reference report email to {target_email=}") email.enqueue_email_from_template( target_email, "reference_report", template_args={ "reference": reference, "from_user_user_link": urls.user_link(username=reference.from_user.username), "to_user_user_link": urls.user_link(username=reference.to_user.username), }, )
def send_report_email(complaint): target_email = config["REPORTS_EMAIL_RECIPIENT"] logger.info(f"Sending report email to {target_email=}") logger.info( f"User {complaint=} reporting user {complaint.reported_user.username=}" ) logger.info(f"Reason: {complaint.reason=}") logger.info(f"Description:") logger.info(f"{complaint.description=}") email.enqueue_email_from_template( target_email, "report", template_args={ "complaint": complaint, }, )
def send_account_deletion_confirmation_email(user): logger.info(f"Sending account deletion confirmation email to {user=}.") logger.info(f"Email for {user.username=} sent to {user.email}.") token = AccountDeletionToken(token=urlsafe_secure_token(), user=user, expiry=now() + timedelta(hours=2)) deletion_link = urls.delete_account_link( account_deletion_token=token.token) email.enqueue_email_from_template( user.email, "account_deletion_confirmation", template_args={ "user": user, "deletion_link": deletion_link }, ) return token