Djanagoはメール送信の機能もありまして、(使っているのはPythonのsmtplibモジュール)ですが、ここで簡単でメモしておきますね。
setting.pyでEMAILのバラメータを作成
まずはsetting.pyの中に以下のコードを追加しますー
EMAIL_HOST='smtp.gmail.com'
EMAIL_HOST_USER='MyExample@gmail.com'
EMAIL_HOST_PASSWORD='MyExamplePassword'
EMAIL_PORT=587
EMAIL_USE_TLS=True
send_mailを呼び出しだけです!らくちん!
from django.shortcuts import render
from django.http import HttpResponse
from django.core.mail import send_mail
debug=False
def homepage(request):
try:
if debug:
send_mail(
subject='*****Testing email*******',
message='Some Text Message',
from_email='MyExample@gmail.com',
recipient_list=['MyExample@XXX.jp', 'MyExample2@XXXX.jp'],
fail_silently=False,
)
except Exception as er:
print(er)