LoginSignup
0
1

More than 5 years have passed since last update.

django#メールを送る

Last updated at Posted at 2019-03-15

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)
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1