def notify_reset_password(self, user: User, reset_password_token: str) -> None: """ Reset password link for user :param user: user to notify :param reset_password_token: token for resetting password """ logger.debug(self, "user: {}".format(user.user_id)) logger.info(self, "Generating reset password email to {}".format(user.email)) translator = Translator(self.config, default_lang=user.lang) email_sender = EmailSender(self.config, self._smtp_config, self.config.EMAIL__NOTIFICATION__ACTIVATED) translated_subject = translator.get_translation( self.config.EMAIL__NOTIFICATION__RESET_PASSWORD_REQUEST__SUBJECT) subject = translated_subject.replace(EST.WEBSITE_TITLE, str(self.config.WEBSITE__TITLE)) from_header = self._get_sender() to_header = EmailAddress(user.get_display_name(), user.email) html_template_file_path = ( self.config. EMAIL__NOTIFICATION__RESET_PASSWORD_REQUEST__TEMPLATE__HTML) # TODO - G.M - 2018-08-17 - Generate token context = { "user": user, "logo_url": get_email_logo_frontend_url(self.config), "reset_password_url": get_reset_password_frontend_url(self.config, token=reset_password_token, email=user.email), } body_html = self._render_template( mako_template_filepath=html_template_file_path, context=context, translator=translator) message = EmailNotificationMessage( subject=subject, from_header=from_header, to_header=to_header, body_html=body_html, lang=translator.default_lang, ) send_email_through(config=self.config, sendmail_callable=email_sender.send_mail, message=message)
def notify_created_account( self, user: User, password: str, origin_user: typing.Optional[User] = None) -> None: """ Send created account email to given user. :param password: choosed password :param user: user to notify """ logger.info(self, "Generating created account mail to {}".format(user.email)) email_sender = EmailSender(self.config, self._smtp_config, self.config.EMAIL__NOTIFICATION__ACTIVATED) translator = Translator(self.config, default_lang=user.lang) translated_subject = translator.get_translation( self.config.EMAIL__NOTIFICATION__CREATED_ACCOUNT__SUBJECT) subject = translated_subject.replace(EST.WEBSITE_TITLE, str(self.config.WEBSITE__TITLE)) from_header = self._get_sender(origin_user) to_header = EmailAddress(user.get_display_name(), user.email) html_template_file_path = self.config.EMAIL__NOTIFICATION__CREATED_ACCOUNT__TEMPLATE__HTML context = { "origin_user": origin_user, "user": user, "password": password, "logo_url": get_email_logo_frontend_url(self.config), "login_url": get_login_frontend_url(self.config), } translator = Translator(self.config, default_lang=user.lang) body_html = self._render_template( mako_template_filepath=html_template_file_path, context=context, translator=translator) message = EmailNotificationMessage( subject=subject, from_header=from_header, to_header=to_header, body_html=body_html, lang=translator.default_lang, ) send_email_through(config=self.config, sendmail_callable=email_sender.send_mail, message=message)
def notify_reset_password(self, user: User, reset_password_token: str) -> None: """ Reset password link for user :param user: user to notify :param reset_password_token: token for resetting password """ logger.debug(self, "user: {}".format(user.user_id)) logger.info(self, "Generating reset password email to {}".format(user.email)) translator = Translator(self.config, default_lang=user.lang) email_sender = EmailSender( self.config, self._smtp_config, self.config.EMAIL__NOTIFICATION__ACTIVATED ) translated_subject = translator.get_translation( self.config.EMAIL__NOTIFICATION__RESET_PASSWORD_REQUEST__SUBJECT ) subject = translated_subject.replace(EST.WEBSITE_TITLE, str(self.config.WEBSITE__TITLE)) message = MIMEMultipart("alternative") message["Subject"] = subject message["From"] = self._get_sender() message["To"] = formataddr((user.get_display_name(), user.email)) html_template_file_path = ( self.config.EMAIL__NOTIFICATION__RESET_PASSWORD_REQUEST__TEMPLATE__HTML ) # TODO - G.M - 2018-08-17 - Generate token context = { "user": user, "logo_url": get_email_logo_frontend_url(self.config), "reset_password_url": get_reset_password_frontend_url( self.config, token=reset_password_token, email=user.email ), } body_html = self._render_template( mako_template_filepath=html_template_file_path, context=context, translator=translator ) part2 = MIMEText(body_html, "html", "utf-8") # Attach parts into message container. # According to RFC 2046, the last part of a multipart message, # in this case the HTML message, is best and preferred. message.attach(part2) send_email_through( config=self.config, sendmail_callable=email_sender.send_mail, message=message )
def notify_created_account(self, user: User, password: str) -> None: """ Send created account email to given user. :param password: choosed password :param user: user to notify """ logger.info(self, "Generating created account mail to {}".format(user.email)) email_sender = EmailSender( self.config, self._smtp_config, self.config.EMAIL__NOTIFICATION__ACTIVATED ) translator = Translator(self.config, default_lang=user.lang) translated_subject = translator.get_translation( self.config.EMAIL__NOTIFICATION__CREATED_ACCOUNT__SUBJECT ) subject = translated_subject.replace(EST.WEBSITE_TITLE, str(self.config.WEBSITE__TITLE)) message = MIMEMultipart("alternative") message["Subject"] = subject message["From"] = self._get_sender() message["To"] = formataddr((user.get_display_name(), user.email)) html_template_file_path = self.config.EMAIL__NOTIFICATION__CREATED_ACCOUNT__TEMPLATE__HTML context = { "user": user, "password": password, "logo_url": get_email_logo_frontend_url(self.config), "login_url": get_login_frontend_url(self.config), } translator = Translator(self.config, default_lang=user.lang) body_html = self._render_template( mako_template_filepath=html_template_file_path, context=context, translator=translator ) part2 = MIMEText(body_html, "html", "utf-8") # Attach parts into message container. # According to RFC 2046, the last part of a multipart message, # in this case the HTML message, is best and preferred. message.attach(part2) send_email_through( config=self.config, sendmail_callable=email_sender.send_mail, message=message )
def notify_reset_password( self, user: User, reset_password_token: str, ) -> None: """ Reset password link for user :param user: user to notify :param reset_password_token: token for resetting password """ logger.debug(self, 'user: {}'.format(user.user_id)) logger.info(self, 'Sending asynchronous email to 1 user ({0})'.format( user.email, )) translator = Translator(self.config, default_lang=user.lang) async_email_sender = EmailSender( self.config, self._smtp_config, self.config.EMAIL_NOTIFICATION_ACTIVATED ) subject = self.config.EMAIL_NOTIFICATION_RESET_PASSWORD_SUBJECT.replace( EST.WEBSITE_TITLE, str(self.config.WEBSITE_TITLE) ) message = MIMEMultipart('alternative') message['Subject'] = subject message['From'] = self._get_sender() message['To'] = formataddr((user.get_display_name(), user.email)) text_template_file_path = self.config.EMAIL_NOTIFICATION_RESET_PASSWORD_TEMPLATE_TEXT # nopep8 html_template_file_path = self.config.EMAIL_NOTIFICATION_RESET_PASSWORD_TEMPLATE_HTML # nopep8 # TODO - G.M - 2018-08-17 - Generate token context = { 'user': user, 'logo_url': get_email_logo_frontend_url(self.config), 'reset_password_url': get_reset_password_frontend_url( self.config, token=reset_password_token, email=user.email, ), } body_text = self._render_template( mako_template_filepath=text_template_file_path, context=context, translator=translator, ) body_html = self._render_template( mako_template_filepath=html_template_file_path, context=context, translator=translator, ) part1 = MIMEText(body_text, 'plain', 'utf-8') part2 = MIMEText(body_html, 'html', 'utf-8') # Attach parts into message container. # According to RFC 2046, the last part of a multipart message, # in this case the HTML message, is best and preferred. message.attach(part1) message.attach(part2) send_email_through( config=self.config, sendmail_callable=async_email_sender.send_mail, message=message )
def notify_created_account( self, user: User, password: str, ) -> None: """ Send created account email to given user. :param password: choosed password :param user: user to notify """ # TODO BS 20160712: Cyclic import logger.debug(self, 'user: {}'.format(user.user_id)) logger.info(self, 'Sending asynchronous email to 1 user ({0})'.format( user.email, )) async_email_sender = EmailSender( self.config, self._smtp_config, self.config.EMAIL_NOTIFICATION_ACTIVATED ) subject = \ self.config.EMAIL_NOTIFICATION_CREATED_ACCOUNT_SUBJECT \ .replace( EST.WEBSITE_TITLE, str(self.config.WEBSITE_TITLE) ) message = MIMEMultipart('alternative') message['Subject'] = subject message['From'] = self._get_sender() message['To'] = formataddr((user.get_display_name(), user.email)) text_template_file_path = self.config.EMAIL_NOTIFICATION_CREATED_ACCOUNT_TEMPLATE_TEXT # nopep8 html_template_file_path = self.config.EMAIL_NOTIFICATION_CREATED_ACCOUNT_TEMPLATE_HTML # nopep8 context = { 'user': user, 'password': password, 'logo_url': get_email_logo_frontend_url(self.config), 'login_url': get_login_frontend_url(self.config), } translator = Translator(self.config, default_lang=user.lang) body_text = self._render_template( mako_template_filepath=text_template_file_path, context=context, translator=translator ) body_html = self._render_template( mako_template_filepath=html_template_file_path, context=context, translator=translator ) part1 = MIMEText(body_text, 'plain', 'utf-8') part2 = MIMEText(body_html, 'html', 'utf-8') # Attach parts into message container. # According to RFC 2046, the last part of a multipart message, # in this case the HTML message, is best and preferred. message.attach(part1) message.attach(part2) send_email_through( config=self.config, sendmail_callable=async_email_sender.send_mail, message=message )