... n() . A new using argument replaces the earlier connection in Django functions that send email. This guide provides details on migrating existing projects to the new mailers functionality. All Django projects that sen ... d email should: If using any third-party packages that send email, verify their compatibility with MAILERS before making other cha ... nges. Update email-related settings . Run with deprecation warnings enabled (see 廃止予定警告を解決する ) to identify other code needing upda ... ... or a file during development and an SMTP server or email service provider in production. コードは django.core.mail モジュールにあります。 簡単な例 簡単なメール送信には send_mail() ... を使用します。たとえば、プレーンテキストのメッセージを送信するには、次のようにします。 from django.core.mail import send_mail send_mail ( "Subject here" , "Here is the message." , "from@example.com" , [ "to@example.com" ], ) When a ... dditional email sending functionality is needed, use the EmailMessage or EmailMultiAlternatives class. For example, to send a multipart em ... ... ects before deleting them. As a consequence, the DB_CASCADE option does not trigger the pre_delete or post_delete signals. Mailers The new MAILERS setting supports configuring multiple email backends with different options, similar to existing mechan ... isms for CACHES , DATABASES , STORAGES , and TASKS : MAILERS = { "default" : { "BACKEND" : "django.core.mail.backends.smtp.EmailBackend" , "OPTIONS" : { "host" : "smtp.example.com" ... , "use_tls" : True }, }, "marketing" : { "BACKEND" : "example.third.party.EmailBackend" , "OPTIONS" : { "region" : "africa-1" }, }, } You can select a mailer with the new using argument to email sending ... ... n Tasks framework for running code outside the HTTP request–response cycle. This enables offloading work, such as sending emails or processing data, to background workers. The framework provides task definition, validation, queuing, and result handli ... ning them continues to belong to external worker processes. Tasks are defined using the task() decorator: from django.core.mail import send_mail from django.tasks import task @task def email_users ( emails , subject , message ): return send_mail ( su ... bject , message , None , emails ) Once defined, tasks can be enqueued through a configured backend: email_users . enqueue ( emails = [ "user@example.com" ... ... keeps requests fast, reduces latency, and improves the user experience. For example, a user shouldn't have to wait for an email to send before their page finishes loading. Django's Tasks framework makes it easy to define and enqueue such work. It doe ... kend Defining Tasks Tasks are defined using the django.tasks.task() decorator on a module-level function: from django.core.mail import send_mail from django.tasks import task @task def email_users ( emails , subject , message ): return send_mail ( su ... bject = subject , message = message , from_email = None , recipient_list = emails ) The return value of the decorator is a Task instance. Task attributes can be customized ... ... alse のとき: django ロガーは、 django ヒエラルキー ( django.server を除く) において、 ERROR ないし CRITICAL レベルを AdminEmailHandler に送信します。 DEBUG の値にかかわらず: django.server ロガーは INFO レベル以上のメッセージをコンソールに送信します。 ... django.server を除く全てのロガーは、ルートの django ロガーまで、親に対してログを伝播させます。 console と mail_admins ハンドラは、上述の動作を提供するためにルートロガーにアタッチされます。 Pythonのデフォルトは、レベル WARNING 以上のレ ... ndler" , }, "django.server" : { "level" : "INFO" , "class" : "logging.StreamHandler" , "formatter" : "django.server" , }, "mail_admins" : { "level" : "ERROR" , "filters" : [ "require_debug_false" ], "class" : "django.utils.log.AdminEmailHandler" , }, ... ... ールバックが呼び出されます。これは、ラップされたコードブロック後のコミットをエミュレートします。 例: from django.core import mail from django.test import TestCase class ContactTests ( TestCase ): def test_post ( self ): with self . captureOnCommitCallb ... self . assertEqual ( response . status_code , 200 ) self . assertEqual ( len ( callbacks ), 1 ) self . assertEqual ( len ( mail . outbox ), 1 ) self . assertEqual ( mail . outbox [ 0 ] . subject , "Contact Form" ) self . assertEqual ( mail . outbox [ ... は各テストケースの開始時に、テスト用のメール送信トレイの中身を消去します。 テスト中のメールサービスの詳細については、以下の Email services を参照してください。 アサーション Python の通常の unittest.TestCase クラスが assertTrue() や assertEqual() のよう ... ... ent of django.core.paginator.Paginator and django.core.paginator.AsyncPaginator will no longer be allowed. The django.core.mail APIs will no longer accept certain parameters as positional arguments. These must be passed as keyword arguments instead. ... Support for passing Python's legacy email email.mime.base.MIMEBase object to EmailMessage.attach() (or including one in the message's attachments list) will be remo ... ved. The django.core.mail.BadHeaderError exception will be removed. The django.core.mail.SafeMIMEText and SafeMIMEMultipart classes will be removed. ... ... r object-level permissions , permissions for anonymous users , and more flexible username requirements . Customization of email sending via email backends . New "smart" if template tag which supports comparison operators. These are just the highlight ... characters, including @ , + , . and - characters. E メールのバックエンド You can now configure the way that Django sends email . Instead of using SMTP to send all email, you can now choose a configurable email backend to send messages. If your hosti ... ng provider uses a sandbox or some other non-SMTP technique for sending mail, you can now construct an email backend that will allow Django's standard mail sending methods to use those facilities. Th ... ... ション --add-location makemessages コマンドラインオプション --addrport testserver コマンドラインオプション --admins sendtestemail コマンドラインオプション --all diffsettings コマンドラインオプション dumpdata コマンドラインオプション makemessages コマン ... tecachetable コマンドラインオプション makemigrations コマンドラインオプション --durations test コマンドラインオプション --email createsuperuser コマンドラインオプション --empty makemigrations コマンドラインオプション --exclude compilemessages コマンド ... ラインオプション --locale compilemessages コマンドラインオプション makemessages コマンドラインオプション --managers sendtestemail コマンドラインオプション --mapping ogrinspect コマンドラインオプション --merge makemigrations コマンドラインオプション --m ... 2026年10月08日