debugging entry
This commit is contained in:
34
rog/utils.py
Normal file
34
rog/utils.py
Normal file
@ -0,0 +1,34 @@
|
||||
import os
|
||||
from django.template.loader import render_to_string
|
||||
from django.conf import settings
|
||||
import logging
|
||||
from django.core.mail import send_mail
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def load_email_template(template_name, context):
|
||||
template_path = os.path.join('email', template_name)
|
||||
email_content = render_to_string(template_path, context)
|
||||
|
||||
# 件名と本文を分離
|
||||
subject, _, body = email_content.partition('\n\n')
|
||||
subject = subject.replace('件名: ', '').strip()
|
||||
|
||||
return subject, body
|
||||
|
||||
def send_activation_email(user, activation_link):
|
||||
context = {
|
||||
'name': user.firstname or user.email,
|
||||
'activation_link': activation_link,
|
||||
'app_download_link': settings.APP_DOWNLOAD_LINK,
|
||||
'service_name': settings.SERVICE_NAME,
|
||||
}
|
||||
|
||||
subject, body = load_email_template('activation_email.txt', context)
|
||||
|
||||
try:
|
||||
send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [user.email], fail_silently=False)
|
||||
logger.info(f"アクティベーションメールを送信しました。 受信者: {user.email}")
|
||||
except Exception as e:
|
||||
logger.error(f"アクティベーションメールの送信に失敗しました。 受信者: {user.email}, エラー: {str(e)}")
|
||||
raise # エラーを再度発生させて、呼び出し元で処理できるようにします
|
||||
Reference in New Issue
Block a user