
Co-authored-by: Yongtao Huang <99629139+hyongtao-db@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com>
47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
import logging
|
|
import time
|
|
|
|
import click
|
|
from celery import shared_task
|
|
|
|
from extensions.ext_mail import mail
|
|
from libs.email_i18n import EmailType, get_email_i18n_service
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@shared_task(queue="mail")
|
|
def send_email_code_login_mail_task(language: str, to: str, code: str) -> None:
|
|
"""
|
|
Send email code login email with internationalization support.
|
|
|
|
Args:
|
|
language: Language code for email localization
|
|
to: Recipient email address
|
|
code: Email verification code
|
|
"""
|
|
if not mail.is_inited():
|
|
return
|
|
|
|
logger.info(click.style(f"Start email code login mail to {to}", fg="green"))
|
|
start_at = time.perf_counter()
|
|
|
|
try:
|
|
email_service = get_email_i18n_service()
|
|
email_service.send_email(
|
|
email_type=EmailType.EMAIL_CODE_LOGIN,
|
|
language_code=language,
|
|
to=to,
|
|
template_context={
|
|
"to": to,
|
|
"code": code,
|
|
},
|
|
)
|
|
|
|
end_at = time.perf_counter()
|
|
logger.info(
|
|
click.style(f"Send email code login mail to {to} succeeded: latency: {end_at - start_at}", fg="green")
|
|
)
|
|
except Exception:
|
|
logger.exception("Send email code login mail to %s failed", to)
|