{"title":"メールを送信する","version":"6.1","locale":"ja","docname":"topics/email","url":"/ja/6.1/topics/email/","canonical":"https://djangodocs.dev/ja/6.1/topics/email/","summary":"Django provides wrappers for Python's email and smtplib modules to simplify composing and sending email.","html":"<span id=\"sending-email\"></span><h1>メールを送信する<a class=\"heading-anchor\" href=\"#module-django.core.mail\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>Django provides wrappers for Python's <a class=\"reference external\" href=\"https://docs.python.org/3/library/email.html#module-email\" title=\"(in Python v3.14)\"><code class=\"xref py py-mod docutils literal notranslate\">email</code></a> and <a class=\"reference external\" href=\"https://docs.python.org/3/library/smtplib.html#module-smtplib\" title=\"(in Python v3.14)\"><code class=\"xref py py-mod docutils literal notranslate\">smtplib</code></a> modules\nto simplify composing and sending email. Django's email framework also supports\nswapping in different delivery mechanisms: you can direct email to the console\nor a file during development and an SMTP server or email service provider in\nproduction.</p>\n<p>コードは <code class=\"docutils literal notranslate\">django.core.mail</code> モジュールにあります。</p>\n<section id=\"quick-examples\">\n<h2>簡単な例<a class=\"heading-anchor\" href=\"#quick-examples\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>簡単なメール送信には <a class=\"reference internal\" href=\"#django.core.mail.send_mail\" title=\"django.core.mail.send_mail\"><code class=\"xref py py-func docutils literal notranslate\">send_mail()</code></a> を使用します。たとえば、プレーンテキストのメッセージを送信するには、次のようにします。</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.core.mail</span> <span class=\"kn\">import</span> send_mail\n\nsend_mail<span class=\"p\">(</span>\n    <span class=\"s2\">&quot;Subject here&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;Here is the message.&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;from@example.com&quot;</span><span class=\"p\">,</span>\n    <span class=\"p\">[</span><span class=\"s2\">&quot;to@example.com&quot;</span><span class=\"p\">],</span>\n<span class=\"p\">)</span>\n</code></pre></div>\n<p>When additional email sending functionality is needed, use the\n<a class=\"reference internal\" href=\"#topic-email-message\"><span class=\"std std-ref\">EmailMessage</span></a> or <a class=\"reference internal\" href=\"#django.core.mail.EmailMultiAlternatives\" title=\"django.core.mail.EmailMultiAlternatives\"><code class=\"xref py py-class docutils literal notranslate\">EmailMultiAlternatives</code></a>\nclass. For example, to send a multipart email that includes both HTML and plain\ntext versions with a specific template and custom headers, you can use the\nfollowing approach:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.core.mail</span> <span class=\"kn\">import</span> EmailMultiAlternatives\n<span class=\"kn\">from</span> <span class=\"nn\">django.template.loader</span> <span class=\"kn\">import</span> render_to_string\n\n<span class=\"c1\"># First, render the plain text content.</span>\ntext_content <span class=\"o\">=</span> render_to_string<span class=\"p\">(</span>\n    <span class=\"s2\">&quot;templates/emails/my_email.txt&quot;</span><span class=\"p\">,</span>\n    context<span class=\"o\">=</span><span class=\"p\">{</span><span class=\"s2\">&quot;my_variable&quot;</span><span class=\"p\">:</span> <span class=\"mi\">42</span><span class=\"p\">},</span>\n<span class=\"p\">)</span>\n\n<span class=\"c1\"># Secondly, render the HTML content.</span>\nhtml_content <span class=\"o\">=</span> render_to_string<span class=\"p\">(</span>\n    <span class=\"s2\">&quot;templates/emails/my_email.html&quot;</span><span class=\"p\">,</span>\n    context<span class=\"o\">=</span><span class=\"p\">{</span><span class=\"s2\">&quot;my_variable&quot;</span><span class=\"p\">:</span> <span class=\"mi\">42</span><span class=\"p\">},</span>\n<span class=\"p\">)</span>\n\n<span class=\"c1\"># Then, create a multipart email instance.</span>\nmsg <span class=\"o\">=</span> EmailMultiAlternatives<span class=\"p\">(</span>\n    subject<span class=\"o\">=</span><span class=\"s2\">&quot;Subject here&quot;</span><span class=\"p\">,</span>\n    body<span class=\"o\">=</span>text_content<span class=\"p\">,</span>\n    from_email<span class=\"o\">=</span><span class=\"s2\">&quot;from@example.com&quot;</span><span class=\"p\">,</span>\n    to<span class=\"o\">=</span><span class=\"p\">[</span><span class=\"s2\">&quot;to@example.com&quot;</span><span class=\"p\">],</span>\n    headers<span class=\"o\">=</span><span class=\"p\">{</span><span class=\"s2\">&quot;List-Unsubscribe&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;&lt;mailto:unsub@example.com&gt;&quot;</span><span class=\"p\">},</span>\n<span class=\"p\">)</span>\n\n<span class=\"c1\"># Lastly, attach the HTML content to the email instance and send.</span>\nmsg<span class=\"o\">.</span>attach_alternative<span class=\"p\">(</span>html_content<span class=\"p\">,</span> <span class=\"s2\">&quot;text/html&quot;</span><span class=\"p\">)</span>\nmsg<span class=\"o\">.</span>send<span class=\"p\">()</span>\n</code></pre></div>\n</section>\n<section id=\"configuring-email\">\n<span id=\"topic-email-configuration\"></span><h2>Configuring email<a class=\"heading-anchor\" href=\"#configuring-email\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>New Django projects are not configured to send email by default. Instead, email\nis printed to the console as a development aid (for projects created with\n<a class=\"reference internal\" href=\"/ja/6.1/ref/django-admin/#django-admin-startproject\"><code class=\"xref std std-djadmin docutils literal notranslate\">startproject</code></a>) or results in a <code class=\"docutils literal notranslate\">MailerDoesNotExist</code> error (when the\n<a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> setting isn't defined).</p>\n<p>Use the <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> setting to tell Django how to send email. For\nexample, to send through an SMTP server running on the local machine:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>MAILERS <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;default&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;BACKEND&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.core.mail.backends.smtp.EmailBackend&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;OPTIONS&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;host&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;localhost&quot;</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p>Django abstracts the email sending process into an &quot;email backend&quot; class.\n<a class=\"reference internal\" href=\"#topic-email-backends\"><span class=\"std std-ref\">メールのバックエンド</span></a> lists the email backends that come with Django.</p>\n<p>The example above uses Django's <a class=\"reference internal\" href=\"#topic-email-smtp-backend\"><span class=\"std std-ref\">SMTP email backend</span></a>, which sends using the standard <a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol\">SMTP</a> protocol.\nThis backend is useful for many production configurations, including SMTP\nservers in your own infrastructure and most commercial email service providers\n(ESPs). There are also <a class=\"reference internal\" href=\"#topic-third-party-email-backends\"><span class=\"std std-ref\">third-party email backends</span></a> available that integrate directly with ESP\nAPIs or add other sending features.</p>\n<p>During development or testing you often don't want to send email at all.\nDjango's test runner <a class=\"reference internal\" href=\"/ja/6.1/topics/testing/tools/#topics-testing-email\"><span class=\"std std-ref\">automatically overrides</span></a> the\n<a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> configuration to substitute Django's <a class=\"reference internal\" href=\"#topic-email-memory-backend\"><span class=\"std std-ref\">memory email\nbackend</span></a>. This prevents test cases from sending\nreal email and gives them access to the messages that would have been sent.\n<a class=\"reference internal\" href=\"#configuring-email-for-development\"><span class=\"std std-ref\">開発用にメールを設定する</span></a> discusses some other\napproaches.</p>\n<aside class=\"version-note version-changed\" data-version=\"6.1\" role=\"note\">\n<p class=\"version-note-title\">Changed in Django 6.1</p><p>In earlier releases, Django defaulted to sending email through an SMTP\nserver running on localhost, using the now-deprecated\n<a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-EMAIL_BACKEND\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_BACKEND</code></a> and related settings.</p>\n</aside>\n<aside class=\"version-note version-deprecated\" data-version=\"6.1\" role=\"note\">\n<p class=\"version-note-title\">Deprecated since Django 6.1</p><p><span class=\"versionmodified deprecated\">バージョン 6.1 で非推奨: </span>Until Django 2028, if the <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> setting is not defined then\nthe earlier behavior still applies: Django will default to using an SMTP\nserver on localhost (but will issue deprecation warnings). Starting in\nDjango 2028, attempts to send email without <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> defined will\nresult in a <code class=\"docutils literal notranslate\">MailerDoesNotExist</code> error.</p>\n<p>Existing projects can opt into the new behavior early by adding\n<a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> to <code class=\"docutils literal notranslate\">settings.py</code>. See <a class=\"reference internal\" href=\"/ja/6.1/howto/mailers-migration/#migrating-to-mailers\"><span class=\"std std-ref\">Migrating email to mailers</span></a>.</p>\n</aside>\n<section id=\"multiple-mailers\">\n<h3>Multiple mailers<a class=\"heading-anchor\" href=\"#multiple-mailers\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Sometimes different types of email need to be sent in different ways: e.g.,\ninternal vs. external email, different SMTP servers for users in different\nregions, using different services for transactional notifications and bulk\nmarketing email, etc.</p>\n<p>The <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> setting can define multiple mail configurations. For\nexample:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">import</span> <span class=\"nn\">os</span>\n\nMAILERS <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;default&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;BACKEND&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.core.mail.backends.smtp.EmailBackend&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;OPTIONS&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;host&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;smtp.example.net&quot;</span><span class=\"p\">,</span>\n            <span class=\"s2\">&quot;use_tls&quot;</span><span class=\"p\">:</span> <span class=\"kc\">True</span><span class=\"p\">,</span>\n            <span class=\"s2\">&quot;username&quot;</span><span class=\"p\">:</span> os<span class=\"o\">.</span>environ<span class=\"p\">[</span><span class=\"s2\">&quot;EMAIL_ACCOUNT_ID&quot;</span><span class=\"p\">],</span>\n            <span class=\"s2\">&quot;password&quot;</span><span class=\"p\">:</span> os<span class=\"o\">.</span>environ<span class=\"p\">[</span><span class=\"s2\">&quot;EMAIL_API_KEY&quot;</span><span class=\"p\">],</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n    <span class=\"s2\">&quot;notifications&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;BACKEND&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;example.third.party.EmailBackend&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;OPTIONS&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;api_key&quot;</span><span class=\"p\">:</span> os<span class=\"o\">.</span>environ<span class=\"p\">[</span><span class=\"s2\">&quot;THIRD_PARTY_API_KEY&quot;</span><span class=\"p\">],</span>\n            <span class=\"s2\">&quot;region&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;eu&quot;</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n    <span class=\"s2\">&quot;admin&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;BACKEND&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.core.mail.backends.smtp.EmailBackend&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;OPTIONS&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;host&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;localhost&quot;</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p>This defines three mailer configurations:</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\">&quot;default&quot;</code> sends through an SMTP server at <code class=\"docutils literal notranslate\">smtp.example.net</code> with a TLS\nsecured connection. It reads an account id and API key from environment\nvariables and uses them as the SMTP authentication username and password.\n(Many SMTP services use some variation of this authentication scheme.)</p></li>\n<li><p><code class=\"docutils literal notranslate\">&quot;notifications&quot;</code> sends through a hypothetical commercial email service,\nusing a third-party EmailBackend that connects directly to their API.\n(See <a class=\"reference internal\" href=\"#topic-third-party-email-backends\"><span class=\"std std-ref\">Third-party backends</span></a> for pointers on locating real,\ncommunity maintained email backend packages.)</p></li>\n<li><p><code class=\"docutils literal notranslate\">&quot;admin&quot;</code> sends through an SMTP server running on <code class=\"docutils literal notranslate\">localhost</code>, with no\nother options required.</p></li>\n</ul>\n<p>With this configuration, you can provide the <code class=\"docutils literal notranslate\">using</code> argument to Django's\n<a class=\"reference internal\" href=\"#topic-email-sending\"><span class=\"std std-ref\">email sending functions</span></a> to specify a particular\nmailer configuration:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.core.mail</span> <span class=\"kn\">import</span> send_mail\n\nsend_mail<span class=\"p\">(</span>\n    <span class=\"s2\">&quot;Account activated&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;Congratulations, you&#39;re all ready to use our Django app!&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;from@example.com&quot;</span><span class=\"p\">,</span>\n    <span class=\"p\">[</span><span class=\"s2\">&quot;user@example.com&quot;</span><span class=\"p\">],</span>\n    using<span class=\"o\">=</span><span class=\"s2\">&quot;notifications&quot;</span><span class=\"p\">,</span>\n<span class=\"p\">)</span>\n</code></pre></div>\n<p>If <code class=\"docutils literal notranslate\">using</code> is not specified, Django uses the mailer defined for the\n<code class=\"docutils literal notranslate\">&quot;default&quot;</code> configuration.</p>\n<p>With reusable apps or Django features that send email for you, there may be an\noption to use a specific mailer configuration. For example, Django's logging\n<a class=\"reference internal\" href=\"/ja/6.1/ref/logging/#django.utils.log.AdminEmailHandler\" title=\"django.utils.log.AdminEmailHandler\"><code class=\"xref py py-class docutils literal notranslate\">AdminEmailHandler</code></a> allows specifying the mailer\nconfiguration in its <code class=\"docutils literal notranslate\">using</code> option.</p>\n</section>\n</section>\n<section id=\"sending-messages\">\n<span id=\"topic-email-sending\"></span><h2>Sending messages<a class=\"heading-anchor\" href=\"#sending-messages\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p><code class=\"xref py py-mod docutils literal notranslate\">django.core.mail</code> provides functions for conveniently sending email, as\nwell as classes for building and sending more complex email messages with\nattachments and multiple content types.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">注釈</p>\n<p><code class=\"docutils literal notranslate\">django.core.mail</code> で送信されるメールの文字セットは、<a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-DEFAULT_CHARSET\"><code class=\"xref std std-setting docutils literal notranslate\">DEFAULT_CHARSET</code></a> 設定の値にセットされます。</p>\n</aside>\n<section id=\"send-mail\">\n<h3><code class=\"docutils literal notranslate\">send_mail()</code><a class=\"heading-anchor\" href=\"#send-mail\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py function\">\n<dt class=\"sig sig-object py\" id=\"django.core.mail.send_mail\">\n<span class=\"sig-name descname\">send_mail</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">subject</em>, <em class=\"sig-param\">message</em>, <em class=\"sig-param\">from_email</em>, <em class=\"sig-param\">recipient_list</em>, <em class=\"sig-param\"><span class=\"keyword-only-separator o\"><abbr title=\"Keyword-only parameters separator (PEP 3102)\">*</abbr></span></em>, <em class=\"sig-param\">fail_silently<span class=\"o\">=</span><span class=\"default_value\">False</span></em>, <em class=\"sig-param\">auth_user<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">auth_password<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">connection<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">html_message<span class=\"o\">=</span><span class=\"default_value\">None</span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.core.mail.send_mail\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p><code class=\"docutils literal notranslate\">django.core.mail.send_mail()</code> sends a single email message.</p>\n<p><code class=\"docutils literal notranslate\">subject</code>、<code class=\"docutils literal notranslate\">message</code>、<code class=\"docutils literal notranslate\">from_email</code>、<code class=\"docutils literal notranslate\">recipient_list</code> の 4 つの引数は必須です。</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\">subject</code>: 文字列。</p></li>\n<li><p><code class=\"docutils literal notranslate\">message</code>: 文字列。</p></li>\n<li><p><code class=\"docutils literal notranslate\">from_email</code>: 文字列。もし <code class=\"docutils literal notranslate\">None</code> なら、 Django は <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-DEFAULT_FROM_EMAIL\"><code class=\"xref std std-setting docutils literal notranslate\">DEFAULT_FROM_EMAIL</code></a> 設定の値を使います。</p></li>\n<li><p><code class=\"docutils literal notranslate\">recipient_list</code>: メールアドレスを表す文字列のリスト。<code class=\"docutils literal notranslate\">recipient_list</code> の各メンバーは、メールメッセージの &quot;To:&quot; フィールドで他の受信者を見ることができます。</p></li>\n</ul>\n<p>The following parameters are optional, and must be given as keyword arguments\nif used.</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\">fail_silently</code>: A boolean, default <code class=\"docutils literal notranslate\">False</code>. If set <code class=\"docutils literal notranslate\">True</code>,\n<code class=\"docutils literal notranslate\">send_mail()</code> will suppress some errors during sending. (The exact\nexceptions ignored depend on the email backend in use.)</p></li>\n<li><p><code class=\"docutils literal notranslate\">auth_user</code>: SMTP サーバー認証のためのユーザー名で、省略可能。指定されなかった場合、Django <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-EMAIL_HOST_USER\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_HOST_USER</code></a> 設定の値を使います。</p></li>\n<li><p><code class=\"docutils literal notranslate\">auth_password</code>: SMTP サーバー認証のためのパスワードで、省略可能。指定されなかった場合、Django は <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-EMAIL_HOST_PASSWORD\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_HOST_PASSWORD</code></a> 設定の値を使います。</p></li>\n<li><p><code class=\"docutils literal notranslate\">connection</code>: メール送信のために使うバックエンドで、省略可能。指定しなかった場合、デフォルトのバックエンドのインスタンスが使われます。詳しくは <a class=\"reference internal\" href=\"#topic-email-backends\"><span class=\"std std-ref\">メールのバックエンド</span></a> を参照してください。</p></li>\n<li><p><code class=\"docutils literal notranslate\">html_message</code>: <code class=\"docutils literal notranslate\">html_message</code> が指定された場合、送信されるメールは <em class=\"mimetype\">multipart/alternative</em> となり、<em class=\"mimetype\">text/plain</em> コンテンツタイプを持つ <code class=\"docutils literal notranslate\">message</code> と <em class=\"mimetype\">text/html</em> コンテンツタイプを持つ <code class=\"docutils literal notranslate\">html_message</code> を合わせ持つものになります。</p></li>\n<li><p><code class=\"docutils literal notranslate\">using</code>: An optional <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> alias to use to send the mail. If\nunspecified, the default mailer configuration will be used.</p></li>\n</ul>\n<p><code class=\"docutils literal notranslate\">fail_silently</code>, <code class=\"docutils literal notranslate\">auth_user</code>, <code class=\"docutils literal notranslate\">auth_password</code>, and <code class=\"docutils literal notranslate\">connection</code> are not\nallowed with the <code class=\"docutils literal notranslate\">using</code> argument.</p>\n<p>返り値は、送信に成功したメッセージの数です (送信されるメッセージが 1 つだけの場合もあるため、<code class=\"docutils literal notranslate\">0</code> や <code class=\"docutils literal notranslate\">1</code> になることもあります)。</p>\n<aside class=\"version-note version-deprecated\" data-version=\"6.0\" role=\"note\">\n<p class=\"version-note-title\">Deprecated since Django 6.0</p><p><span class=\"versionmodified deprecated\">バージョン 6.0 で非推奨: </span>Passing <code class=\"docutils literal notranslate\">fail_silently</code> and later parameters as positional arguments is\ndeprecated.</p>\n</aside>\n<aside class=\"version-note version-deprecated\" data-version=\"6.1\" role=\"note\">\n<p class=\"version-note-title\">Deprecated since Django 6.1</p><p><span class=\"versionmodified deprecated\">バージョン 6.1 で非推奨: </span>The <code class=\"docutils literal notranslate\">fail_silently</code>, <code class=\"docutils literal notranslate\">auth_user</code>, <code class=\"docutils literal notranslate\">auth_password</code>, and <code class=\"docutils literal notranslate\">connection</code>\narguments are deprecated. In most cases they can be replaced by <code class=\"docutils literal notranslate\">using</code>\nwith an appropriate <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> configuration. See\n<a class=\"reference internal\" href=\"/ja/6.1/howto/mailers-migration/#migrating-to-mailers-fail-silently\"><span class=\"std std-ref\">Replacing fail_silently</span></a>,\n<a class=\"reference internal\" href=\"/ja/6.1/howto/mailers-migration/#migrating-to-mailers-auth\"><span class=\"std std-ref\">Replacing auth_user and auth_password</span></a>, and\n<a class=\"reference internal\" href=\"/ja/6.1/howto/mailers-migration/#migrating-to-mailers-get-connection\"><span class=\"std std-ref\">Replacing get_connection() and connection arguments</span></a>.</p>\n</aside>\n<aside class=\"version-note version-changed\" data-version=\"6.1\" role=\"note\">\n<p class=\"version-note-title\">Changed in Django 6.1</p><p><code class=\"docutils literal notranslate\">using</code> 引数が追加されました。</p>\n<p>Older versions ignored <code class=\"docutils literal notranslate\">fail_silently=True</code>, <code class=\"docutils literal notranslate\">auth_user</code>,\nand <code class=\"docutils literal notranslate\">auth_password</code> when a <code class=\"docutils literal notranslate\">connection</code> was also provided.\nThis now raises a <code class=\"docutils literal notranslate\">TypeError</code>.</p>\n</aside>\n</section>\n<section id=\"send-mass-mail\">\n<h3><code class=\"docutils literal notranslate\">send_mass_mail()</code><a class=\"heading-anchor\" href=\"#send-mass-mail\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py function\">\n<dt class=\"sig sig-object py\" id=\"django.core.mail.send_mass_mail\">\n<span class=\"sig-name descname\">send_mass_mail</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">datatuple</em>, <em class=\"sig-param\"><span class=\"keyword-only-separator o\"><abbr title=\"Keyword-only parameters separator (PEP 3102)\">*</abbr></span></em>, <em class=\"sig-param\">fail_silently<span class=\"o\">=</span><span class=\"default_value\">False</span></em>, <em class=\"sig-param\">auth_user<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">auth_password<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">connection<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">using<span class=\"o\">=</span><span class=\"default_value\">None</span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.core.mail.send_mass_mail\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p><code class=\"docutils literal notranslate\">django.core.mail.send_mass_mail()</code> は、大量のメール送信を扱うために用意されています。</p>\n<p><code class=\"docutils literal notranslate\">datatuple</code> はメッセージの集合を表すタプルです。タプル内の各要素は、それぞれ1種類のメッセージを表すタプルであり、次の形式を持ちます。</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"p\">(</span>subject<span class=\"p\">,</span> message<span class=\"p\">,</span> from_email<span class=\"p\">,</span> recipient_list<span class=\"p\">)</span>\n</code></pre></div>\n<p><code class=\"docutils literal notranslate\">fail_silently</code>, <code class=\"docutils literal notranslate\">auth_user</code>, <code class=\"docutils literal notranslate\">auth_password</code> and <code class=\"docutils literal notranslate\">connection</code> have the\nsame functions as in <a class=\"reference internal\" href=\"#django.core.mail.send_mail\" title=\"django.core.mail.send_mail\"><code class=\"xref py py-func docutils literal notranslate\">send_mail()</code></a>. They must be given as keyword arguments\nif used, and are not allowed with the <code class=\"docutils literal notranslate\">using</code> argument.</p>\n<p>The keyword argument <code class=\"docutils literal notranslate\">using</code> is an optional <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> alias to use\nto send the mail. If unspecified, the default mailer configuration will be\nused.</p>\n<p>Each separate element of <code class=\"docutils literal notranslate\">datatuple</code> results in a separate email message.\nAs in <a class=\"reference internal\" href=\"#django.core.mail.send_mail\" title=\"django.core.mail.send_mail\"><code class=\"xref py py-func docutils literal notranslate\">send_mail()</code></a>, recipients in the same <code class=\"docutils literal notranslate\">recipient_list</code> will all see\nthe other addresses in the email messages' &quot;To:&quot; field.</p>\n<p>たとえば、次のコードは異なる 2 つのメッセージを 異なる 2 つの受信者のセットに送信します。しかし、メールサーバーへのコネクションは 1 つしか開かれません。</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>message1 <span class=\"o\">=</span> <span class=\"p\">(</span>\n    <span class=\"s2\">&quot;Subject here&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;Here is the message&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;from@example.com&quot;</span><span class=\"p\">,</span>\n    <span class=\"p\">[</span><span class=\"s2\">&quot;first@example.com&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;other@example.com&quot;</span><span class=\"p\">],</span>\n<span class=\"p\">)</span>\nmessage2 <span class=\"o\">=</span> <span class=\"p\">(</span>\n    <span class=\"s2\">&quot;Another Subject&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;Here is another message&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;from@example.com&quot;</span><span class=\"p\">,</span>\n    <span class=\"p\">[</span><span class=\"s2\">&quot;second@test.com&quot;</span><span class=\"p\">],</span>\n<span class=\"p\">)</span>\nsend_mass_mail<span class=\"p\">((</span>message1<span class=\"p\">,</span> message2<span class=\"p\">))</span>\n</code></pre></div>\n<p>戻り値は、メッセージ送信に成功した数です。</p>\n<aside class=\"version-note version-deprecated\" data-version=\"6.0\" role=\"note\">\n<p class=\"version-note-title\">Deprecated since Django 6.0</p><p><span class=\"versionmodified deprecated\">バージョン 6.0 で非推奨: </span>Passing <code class=\"docutils literal notranslate\">fail_silently</code> and later parameters as positional arguments is\ndeprecated.</p>\n</aside>\n<aside class=\"version-note version-deprecated\" data-version=\"6.1\" role=\"note\">\n<p class=\"version-note-title\">Deprecated since Django 6.1</p><p><span class=\"versionmodified deprecated\">バージョン 6.1 で非推奨: </span>The <code class=\"docutils literal notranslate\">fail_silently</code>, <code class=\"docutils literal notranslate\">auth_user</code>, <code class=\"docutils literal notranslate\">auth_password</code>, and <code class=\"docutils literal notranslate\">connection</code>\narguments are deprecated. In most cases they can be replaced by <code class=\"docutils literal notranslate\">using</code>\nwith an appropriate <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> configuration. See\n<a class=\"reference internal\" href=\"/ja/6.1/howto/mailers-migration/#migrating-to-mailers-fail-silently\"><span class=\"std std-ref\">Replacing fail_silently</span></a>,\n<a class=\"reference internal\" href=\"/ja/6.1/howto/mailers-migration/#migrating-to-mailers-auth\"><span class=\"std std-ref\">Replacing auth_user and auth_password</span></a>, and\n<a class=\"reference internal\" href=\"/ja/6.1/howto/mailers-migration/#migrating-to-mailers-get-connection\"><span class=\"std std-ref\">Replacing get_connection() and connection arguments</span></a>.</p>\n</aside>\n<aside class=\"version-note version-changed\" data-version=\"6.1\" role=\"note\">\n<p class=\"version-note-title\">Changed in Django 6.1</p><p><code class=\"docutils literal notranslate\">using</code> 引数が追加されました。</p>\n<p>Older versions ignored <code class=\"docutils literal notranslate\">fail_silently=True</code>, <code class=\"docutils literal notranslate\">auth_user</code>,\nand <code class=\"docutils literal notranslate\">auth_password</code> when a <code class=\"docutils literal notranslate\">connection</code> was also provided.\nThis now raises a <code class=\"docutils literal notranslate\">TypeError</code>.</p>\n</aside>\n<section id=\"send-mass-mail-vs-send-mail\">\n<h4><code class=\"docutils literal notranslate\">send_mass_mail()</code> と <code class=\"docutils literal notranslate\">send_mail()</code> の比較<a class=\"heading-anchor\" href=\"#send-mass-mail-vs-send-mail\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>The main difference between <a class=\"reference internal\" href=\"#django.core.mail.send_mass_mail\" title=\"django.core.mail.send_mass_mail\"><code class=\"xref py py-func docutils literal notranslate\">send_mass_mail()</code></a> and repeatedly calling\n<a class=\"reference internal\" href=\"#django.core.mail.send_mail\" title=\"django.core.mail.send_mail\"><code class=\"xref py py-func docutils literal notranslate\">send_mail()</code></a> is that <a class=\"reference internal\" href=\"#django.core.mail.send_mail\" title=\"django.core.mail.send_mail\"><code class=\"xref py py-func docutils literal notranslate\">send_mail()</code></a> opens a connection to the mail\nserver each time it's executed, while <a class=\"reference internal\" href=\"#django.core.mail.send_mass_mail\" title=\"django.core.mail.send_mass_mail\"><code class=\"xref py py-func docutils literal notranslate\">send_mass_mail()</code></a> uses a single\nconnection for all of its messages. This makes <a class=\"reference internal\" href=\"#django.core.mail.send_mass_mail\" title=\"django.core.mail.send_mass_mail\"><code class=\"xref py py-func docutils literal notranslate\">send_mass_mail()</code></a> slightly\nmore efficient.</p>\n<p><a class=\"reference internal\" href=\"#django.core.mail.send_mail\" title=\"django.core.mail.send_mail\"><code class=\"xref py py-func docutils literal notranslate\">send_mail()</code></a> with multiple <code class=\"docutils literal notranslate\">to</code> addresses sends a single email message,\nwith <code class=\"docutils literal notranslate\">john&#64;example.com</code> and <code class=\"docutils literal notranslate\">jane&#64;example.com</code> both appearing in the &quot;To:&quot;\nfield:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>send_mail<span class=\"p\">(</span>\n    <span class=\"s2\">&quot;Subject&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;Message.&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;from@example.com&quot;</span><span class=\"p\">,</span>\n    <span class=\"p\">[</span><span class=\"s2\">&quot;john@example.com&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;jane@example.com&quot;</span><span class=\"p\">],</span>\n<span class=\"p\">)</span>\n</code></pre></div>\n<p><a class=\"reference internal\" href=\"#django.core.mail.send_mass_mail\" title=\"django.core.mail.send_mass_mail\"><code class=\"xref py py-func docutils literal notranslate\">send_mass_mail()</code></a> sends a separate message per <code class=\"docutils literal notranslate\">datatuple</code> element, so\n<code class=\"docutils literal notranslate\">john&#64;example.com</code> and <code class=\"docutils literal notranslate\">jane&#64;example.com</code> each receive their own email:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>datatuple <span class=\"o\">=</span> <span class=\"p\">(</span>\n    <span class=\"p\">(</span><span class=\"s2\">&quot;Subject&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Message.&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;from@example.com&quot;</span><span class=\"p\">,</span> <span class=\"p\">[</span><span class=\"s2\">&quot;john@example.com&quot;</span><span class=\"p\">]),</span>\n    <span class=\"p\">(</span><span class=\"s2\">&quot;Subject&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Message.&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;from@example.com&quot;</span><span class=\"p\">,</span> <span class=\"p\">[</span><span class=\"s2\">&quot;jane@example.com&quot;</span><span class=\"p\">]),</span>\n<span class=\"p\">)</span>\nsend_mass_mail<span class=\"p\">(</span>datatuple<span class=\"p\">)</span>\n</code></pre></div>\n</section>\n</section>\n<section id=\"mail-admins\">\n<h3><code class=\"docutils literal notranslate\">mail_admins()</code><a class=\"heading-anchor\" href=\"#mail-admins\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py function\">\n<dt class=\"sig sig-object py\" id=\"django.core.mail.mail_admins\">\n<span class=\"sig-name descname\">mail_admins</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">subject</em>, <em class=\"sig-param\">message</em>, <em class=\"sig-param\"><span class=\"keyword-only-separator o\"><abbr title=\"Keyword-only parameters separator (PEP 3102)\">*</abbr></span></em>, <em class=\"sig-param\">fail_silently<span class=\"o\">=</span><span class=\"default_value\">False</span></em>, <em class=\"sig-param\">connection<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">html_message<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">using<span class=\"o\">=</span><span class=\"default_value\">None</span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.core.mail.mail_admins\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p><code class=\"docutils literal notranslate\">django.core.mail.mail_admins()</code> は、<a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-ADMINS\"><code class=\"xref std std-setting docutils literal notranslate\">ADMINS</code></a> 設定で定義されているサイト管理者 (admin) に対してメールを送信するためのショートカットです。</p>\n<p><code class=\"docutils literal notranslate\">mail_admins()</code> は件名の前に <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-EMAIL_SUBJECT_PREFIX\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_SUBJECT_PREFIX</code></a> 設定の値を付けますが、デフォルトでは <code class=\"docutils literal notranslate\">&quot;[Django] &quot;</code> です。</p>\n<p>メールの &quot;From: &quot; ヘッダは <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-SERVER_EMAIL\"><code class=\"xref std std-setting docutils literal notranslate\">SERVER_EMAIL</code></a> 設定の値になります。</p>\n<p>このメソッドは利便性と読みやすさのために存在します。</p>\n<p><code class=\"docutils literal notranslate\">html_message</code> が指定された場合、送信されるメールは <em class=\"mimetype\">multipart/alternative</em> となり、<em class=\"mimetype\">text/plain</em> コンテンツタイプを持つ <code class=\"docutils literal notranslate\">message</code> と <em class=\"mimetype\">text/html</em> コンテンツタイプを持つ <code class=\"docutils literal notranslate\">html_message</code> を合わせ持つものになります。</p>\n<p>The keyword argument <code class=\"docutils literal notranslate\">using</code> is an optional <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> alias to use\nto send the mail. If unspecified, the default mailer configuration will be\nused.</p>\n<aside class=\"version-note version-deprecated\" data-version=\"6.0\" role=\"note\">\n<p class=\"version-note-title\">Deprecated since Django 6.0</p><p><span class=\"versionmodified deprecated\">バージョン 6.0 で非推奨: </span>Passing <code class=\"docutils literal notranslate\">fail_silently</code> and later parameters as positional arguments is\ndeprecated.</p>\n</aside>\n<aside class=\"version-note version-deprecated\" data-version=\"6.1\" role=\"note\">\n<p class=\"version-note-title\">Deprecated since Django 6.1</p><p><span class=\"versionmodified deprecated\">バージョン 6.1 で非推奨: </span>The <code class=\"docutils literal notranslate\">fail_silently</code> and <code class=\"docutils literal notranslate\">connection</code> arguments are deprecated. In most\ncases they can be replaced by <code class=\"docutils literal notranslate\">using</code> with an appropriate\n<a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> configuration. See\n<a class=\"reference internal\" href=\"/ja/6.1/howto/mailers-migration/#migrating-to-mailers-fail-silently\"><span class=\"std std-ref\">Replacing fail_silently</span></a> and\n<a class=\"reference internal\" href=\"/ja/6.1/howto/mailers-migration/#migrating-to-mailers-get-connection\"><span class=\"std std-ref\">Replacing get_connection() and connection arguments</span></a>.</p>\n</aside>\n<aside class=\"version-note version-changed\" data-version=\"6.1\" role=\"note\">\n<p class=\"version-note-title\">Changed in Django 6.1</p><p><code class=\"docutils literal notranslate\">using</code> 引数が追加されました。</p>\n<p>Older versions ignored <code class=\"docutils literal notranslate\">fail_silently=True</code> when a <code class=\"docutils literal notranslate\">connection</code>\nwas also provided. This now raises a <code class=\"docutils literal notranslate\">TypeError</code>.</p>\n</aside>\n</section>\n<section id=\"mail-managers\">\n<h3><code class=\"docutils literal notranslate\">mail_managers()</code><a class=\"heading-anchor\" href=\"#mail-managers\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<dl class=\"py function\">\n<dt class=\"sig sig-object py\" id=\"django.core.mail.mail_managers\">\n<span class=\"sig-name descname\">mail_managers</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">subject</em>, <em class=\"sig-param\">message</em>, <em class=\"sig-param\"><span class=\"keyword-only-separator o\"><abbr title=\"Keyword-only parameters separator (PEP 3102)\">*</abbr></span></em>, <em class=\"sig-param\">fail_silently<span class=\"o\">=</span><span class=\"default_value\">False</span></em>, <em class=\"sig-param\">connection<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">html_message<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">using<span class=\"o\">=</span><span class=\"default_value\">None</span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.core.mail.mail_managers\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd></dd></dl>\n\n<p><code class=\"docutils literal notranslate\">django.core.mail.mail_managers()</code> は、<code class=\"docutils literal notranslate\">mail_admins()</code> とほぼ同じで、<a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MANAGERS\"><code class=\"xref std std-setting docutils literal notranslate\">MANAGERS</code></a> 設定で定義されているサイト管理者 (manager) にメールを送信します。</p>\n<p>The keyword argument <code class=\"docutils literal notranslate\">using</code> is an optional <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> alias to use\nto send the mail. If unspecified, the default mailer configuration will be\nused.</p>\n<aside class=\"version-note version-deprecated\" data-version=\"6.0\" role=\"note\">\n<p class=\"version-note-title\">Deprecated since Django 6.0</p><p><span class=\"versionmodified deprecated\">バージョン 6.0 で非推奨: </span>Passing <code class=\"docutils literal notranslate\">fail_silently</code> and later parameters as positional arguments is\ndeprecated.</p>\n</aside>\n<aside class=\"version-note version-deprecated\" data-version=\"6.1\" role=\"note\">\n<p class=\"version-note-title\">Deprecated since Django 6.1</p><p><span class=\"versionmodified deprecated\">バージョン 6.1 で非推奨: </span>The <code class=\"docutils literal notranslate\">fail_silently</code> and <code class=\"docutils literal notranslate\">connection</code> arguments are deprecated. In most\ncases they can be replaced by <code class=\"docutils literal notranslate\">using</code> with an appropriate\n<a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> configuration. See\n<a class=\"reference internal\" href=\"/ja/6.1/howto/mailers-migration/#migrating-to-mailers-fail-silently\"><span class=\"std std-ref\">Replacing fail_silently</span></a> and\n<a class=\"reference internal\" href=\"/ja/6.1/howto/mailers-migration/#migrating-to-mailers-get-connection\"><span class=\"std std-ref\">Replacing get_connection() and connection arguments</span></a>.</p>\n</aside>\n<aside class=\"version-note version-changed\" data-version=\"6.1\" role=\"note\">\n<p class=\"version-note-title\">Changed in Django 6.1</p><p><code class=\"docutils literal notranslate\">using</code> 引数が追加されました。</p>\n<p>Older versions ignored <code class=\"docutils literal notranslate\">fail_silently=True</code> when a <code class=\"docutils literal notranslate\">connection</code>\nwas also provided. This now raises a <code class=\"docutils literal notranslate\">TypeError</code>.</p>\n</aside>\n</section>\n<section id=\"the-emailmessage-class\">\n<span id=\"topic-email-message\"></span><h3><code class=\"docutils literal notranslate\">EmailMessage</code> クラス<a class=\"heading-anchor\" href=\"#the-emailmessage-class\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Django's <a class=\"reference internal\" href=\"#django.core.mail.send_mail\" title=\"django.core.mail.send_mail\"><code class=\"xref py py-func docutils literal notranslate\">send_mail()</code></a> and <a class=\"reference internal\" href=\"#django.core.mail.send_mass_mail\" title=\"django.core.mail.send_mass_mail\"><code class=\"xref py py-meth docutils literal notranslate\">send_mass_mail()</code></a> functions are actually\nthin wrappers that make use of the <a class=\"reference internal\" href=\"#django.core.mail.EmailMessage\" title=\"django.core.mail.EmailMessage\"><code class=\"xref py py-class docutils literal notranslate\">EmailMessage</code></a> class.</p>\n<p>Not all features of the <a class=\"reference internal\" href=\"#django.core.mail.EmailMessage\" title=\"django.core.mail.EmailMessage\"><code class=\"xref py py-class docutils literal notranslate\">EmailMessage</code></a> class are available through the\n<a class=\"reference internal\" href=\"#django.core.mail.send_mail\" title=\"django.core.mail.send_mail\"><code class=\"xref py py-func docutils literal notranslate\">send_mail()</code></a> and related wrapper functions. If you wish to use advanced\nfeatures, such as BCC'ed recipients, file attachments, or multi-part email,\nyou'll need to create <a class=\"reference internal\" href=\"#django.core.mail.EmailMessage\" title=\"django.core.mail.EmailMessage\"><code class=\"xref py py-class docutils literal notranslate\">EmailMessage</code></a> instances directly.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">注釈</p>\n<p>This is a design feature. <a class=\"reference internal\" href=\"#django.core.mail.send_mail\" title=\"django.core.mail.send_mail\"><code class=\"xref py py-func docutils literal notranslate\">send_mail()</code></a> and related functions were\noriginally the only interface Django provided. However, the list of\nparameters they accepted was slowly growing over time. It made sense to\nmove to a more object-oriented design for email messages and retain the\noriginal functions only for backwards compatibility.</p>\n</aside>\n<p><a class=\"reference internal\" href=\"#django.core.mail.EmailMessage\" title=\"django.core.mail.EmailMessage\"><code class=\"xref py py-class docutils literal notranslate\">EmailMessage</code></a> is responsible for creating the email message itself. The\n<a class=\"reference internal\" href=\"#topic-email-backends\"><span class=\"std std-ref\">email backend</span></a> is then responsible for sending the\nemail.</p>\n<p>For convenience, <a class=\"reference internal\" href=\"#django.core.mail.EmailMessage\" title=\"django.core.mail.EmailMessage\"><code class=\"xref py py-class docutils literal notranslate\">EmailMessage</code></a> provides a <a class=\"reference internal\" href=\"#django.core.mail.EmailMessage.send\" title=\"django.core.mail.EmailMessage.send\"><code class=\"xref py py-meth docutils literal notranslate\">send()</code></a>\nmethod for sending a single email. If you need to send multiple messages, the\nemail backend API <a class=\"reference internal\" href=\"#topics-sending-multiple-emails\"><span class=\"std std-ref\">provides an alternative</span></a>.</p>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.core.mail.EmailMessage\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">EmailMessage</span><a class=\"heading-anchor\" href=\"#django.core.mail.EmailMessage\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>The <code class=\"xref py py-class docutils literal notranslate\">EmailMessage</code> class is initialized with the following\nparameters. All parameters are optional and can be set at any time prior\nto calling the <a class=\"reference internal\" href=\"#django.core.mail.EmailMessage.send\" title=\"django.core.mail.EmailMessage.send\"><code class=\"xref py py-meth docutils literal notranslate\">send()</code></a> method.</p>\n<p>The first four parameters can be passed as positional or keyword arguments,\nbut must be in the given order if positional arguments are used:</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\">subject</code>: メールの件名の行。</p></li>\n<li><p><code class=\"docutils literal notranslate\">body</code>: 本文のテキスト。プレーンテキストのメッセージでなければなりません。</p></li>\n<li><p><code class=\"docutils literal notranslate\">from_email</code>: The sender's address. Both <code class=\"docutils literal notranslate\">fred&#64;example.com</code> and\n<code class=\"docutils literal notranslate\">&quot;Fred&quot; &lt;fred&#64;example.com&gt;</code> forms are supported (see\n<a class=\"reference internal\" href=\"#formatting-addresses\"><span class=\"std std-ref\">Formatting email addresses</span></a>). If omitted, the\n<a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-DEFAULT_FROM_EMAIL\"><code class=\"xref std std-setting docutils literal notranslate\">DEFAULT_FROM_EMAIL</code></a> setting is used.</p></li>\n<li><p><code class=\"docutils literal notranslate\">to</code>: 受信者のメールアドレスのリストまたはタプル。</p></li>\n</ul>\n<p>The following parameters must be given as keyword arguments if used:</p>\n<ul>\n<li><p>メールを送信するときに &quot;Cc&quot; ヘッダ内で使われる、受信者のアドレスのリストまたはタプル。</p></li>\n<li><p><code class=\"docutils literal notranslate\">bcc</code>: A list or tuple of addresses used for blind carbon copies when\nsending the email.</p></li>\n<li><p><code class=\"docutils literal notranslate\">reply_to</code>: メールを送信するときに &quot;Reply-To&quot; ヘッダ内で使われる、受信者のアドレスのリストまたはタプル。</p></li>\n<li><p><code class=\"docutils literal notranslate\">attachments</code>: A list of attachments to put on the message. Each can\nbe an instance of <a class=\"reference external\" href=\"https://docs.python.org/3/library/email.message.html#email.message.MIMEPart\" title=\"(in Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">MIMEPart</code></a> or\n<a class=\"reference internal\" href=\"#django.core.mail.EmailAttachment\" title=\"django.core.mail.EmailAttachment\"><code class=\"xref py py-class docutils literal notranslate\">EmailAttachment</code></a>, or a tuple with attributes\n<code class=\"docutils literal notranslate\">(filename, content, mimetype)</code>.</p>\n<aside class=\"version-note version-changed\" data-version=\"6.0\" role=\"note\">\n<p class=\"version-note-title\">Changed in Django 6.0</p><p>Support for <a class=\"reference external\" href=\"https://docs.python.org/3/library/email.message.html#email.message.MIMEPart\" title=\"(in Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">MIMEPart</code></a> objects in the\n<code class=\"docutils literal notranslate\">attachments</code> list was added.</p>\n</aside>\n<aside class=\"version-note version-deprecated\" data-version=\"6.0\" role=\"note\">\n<p class=\"version-note-title\">Deprecated since Django 6.0</p><p><span class=\"versionmodified deprecated\">バージョン 6.0 で非推奨: </span>Support for Python's legacy <a class=\"reference external\" href=\"https://docs.python.org/3/library/email.mime.html#email.mime.base.MIMEBase\" title=\"(in Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">MIMEBase</code></a>\nobjects in <code class=\"docutils literal notranslate\">attachments</code> is deprecated. Use\n<a class=\"reference external\" href=\"https://docs.python.org/3/library/email.message.html#email.message.MIMEPart\" title=\"(in Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">MIMEPart</code></a> instead.</p>\n</aside>\n</li>\n<li><p><code class=\"docutils literal notranslate\">headers</code>: メッセージに追加するヘッダーの辞書。キーはヘッダ名、値はヘッダ値です。メールメッセージに対して適切なヘッダ名と値にするのは、呼び出す側の責任です。対応する属性は <code class=\"docutils literal notranslate\">extra_headers</code> です。</p></li>\n<li><p><code class=\"docutils literal notranslate\">connection</code>: An <a class=\"reference internal\" href=\"#topic-email-backends\"><span class=\"std std-ref\">email backend</span></a> instance.\nThis parameter is ignored when using\n<a class=\"reference internal\" href=\"#topics-sending-multiple-emails\"><span class=\"std std-ref\">send_messages()</span></a>.</p>\n<aside class=\"version-note version-deprecated\" data-version=\"6.1\" role=\"note\">\n<p class=\"version-note-title\">Deprecated since Django 6.1</p><p><span class=\"versionmodified deprecated\">バージョン 6.1 で非推奨: </span>The <code class=\"docutils literal notranslate\">connection</code> argument is deprecated. Instead, define a\n<a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> configuration with the desired connection options,\nand then call <a class=\"reference internal\" href=\"#django.core.mail.EmailMessage.send\" title=\"django.core.mail.EmailMessage.send\"><code class=\"xref py py-meth docutils literal notranslate\">EmailMessage.send(using=&quot;...&quot;)</code></a> with that\nconfiguration's alias. See <a class=\"reference internal\" href=\"/ja/6.1/howto/mailers-migration/#migrating-to-mailers\"><span class=\"std std-ref\">Migrating email to mailers</span></a>.</p>\n</aside>\n</li>\n</ul>\n<aside class=\"version-note version-deprecated\" data-version=\"6.0\" role=\"note\">\n<p class=\"version-note-title\">Deprecated since Django 6.0</p><p><span class=\"versionmodified deprecated\">バージョン 6.0 で非推奨: </span>Passing all except the first four parameters as positional arguments is\ndeprecated.</p>\n</aside>\n<p>例:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.core.mail</span> <span class=\"kn\">import</span> EmailMessage\n\nemail <span class=\"o\">=</span> EmailMessage<span class=\"p\">(</span>\n    subject<span class=\"o\">=</span><span class=\"s2\">&quot;Hello&quot;</span><span class=\"p\">,</span>\n    body<span class=\"o\">=</span><span class=\"s2\">&quot;Body goes here&quot;</span><span class=\"p\">,</span>\n    from_email<span class=\"o\">=</span><span class=\"s2\">&quot;from@example.com&quot;</span><span class=\"p\">,</span>\n    to<span class=\"o\">=</span><span class=\"p\">[</span><span class=\"s2\">&quot;to1@example.com&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;to2@example.com&quot;</span><span class=\"p\">],</span>\n    bcc<span class=\"o\">=</span><span class=\"p\">[</span><span class=\"s2\">&quot;bcc@example.com&quot;</span><span class=\"p\">],</span>\n    reply_to<span class=\"o\">=</span><span class=\"p\">[</span><span class=\"s2\">&quot;another@example.com&quot;</span><span class=\"p\">],</span>\n    headers<span class=\"o\">=</span><span class=\"p\">{</span><span class=\"s2\">&quot;Message-ID&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;foo&quot;</span><span class=\"p\">},</span>\n<span class=\"p\">)</span>\n</code></pre></div>\n<p>このクラスには以下のメソッドがあります。</p>\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.core.mail.EmailMessage.send\">\n<span class=\"sig-name descname\">send</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">fail_silently<span class=\"o\">=</span><span class=\"default_value\">False</span></em>, <em class=\"sig-param\"><span class=\"keyword-only-separator o\"><abbr title=\"Keyword-only parameters separator (PEP 3102)\">*</abbr></span></em>, <em class=\"sig-param\">using<span class=\"o\">=</span><span class=\"default_value\">None</span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.core.mail.EmailMessage.send\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Sends the message. Returns <code class=\"docutils literal notranslate\">1</code> if the message was sent successfully,\notherwise <code class=\"docutils literal notranslate\">0</code>. (An empty list of recipients returns <code class=\"docutils literal notranslate\">0</code> -- it will\nnot raise an exception.)</p>\n<p>The optional <code class=\"docutils literal notranslate\">using</code> keyword argument specifies a <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a>\nalias to use to send the mail. If not given, the default mailer\nconfiguration will be used.</p>\n<p>If a deprecated connection was specified when the email was\nconstructed, that connection will be used. Providing both a connection\nand <code class=\"docutils literal notranslate\">using</code> will raise an error.</p>\n<p>If the deprecated keyword argument <code class=\"docutils literal notranslate\">fail_silently</code> is <code class=\"docutils literal notranslate\">True</code>,\ncertain backend-dependent exceptions while sending the message will be\nignored. Providing both <code class=\"docutils literal notranslate\">fail_silently</code> and <code class=\"docutils literal notranslate\">using</code> will raise an\nerror.</p>\n<aside class=\"version-note version-changed\" data-version=\"6.1\" role=\"note\">\n<p class=\"version-note-title\">Changed in Django 6.1</p><p><code class=\"docutils literal notranslate\">using</code> 引数が追加されました。</p>\n<p>Older versions ignored <code class=\"docutils literal notranslate\">fail_silently=True</code> when a <code class=\"docutils literal notranslate\">connection</code>\nwas also provided. This now raises a <code class=\"docutils literal notranslate\">TypeError</code>.</p>\n</aside>\n<aside class=\"version-note version-deprecated\" data-version=\"6.1\" role=\"note\">\n<p class=\"version-note-title\">Deprecated since Django 6.1</p><p><span class=\"versionmodified deprecated\">バージョン 6.1 で非推奨: </span>The <code class=\"docutils literal notranslate\">fail_silently</code> argument is deprecated. See\n<a class=\"reference internal\" href=\"/ja/6.1/howto/mailers-migration/#migrating-to-mailers-fail-silently\"><span class=\"std std-ref\">Replacing fail_silently</span></a> for alternatives.</p>\n</aside>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.core.mail.EmailMessage.message\">\n<span class=\"sig-name descname\">message</span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"keyword-only-separator o\"><abbr title=\"Keyword-only parameters separator (PEP 3102)\">*</abbr></span></em>, <em class=\"sig-param\">policy<span class=\"o\">=</span><span class=\"default_value\">email.policy.default</span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.core.mail.EmailMessage.message\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Constructs and returns a Python <a class=\"reference external\" href=\"https://docs.python.org/3/library/email.message.html#email.message.EmailMessage\" title=\"(in Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">email.message.EmailMessage</code></a>\nobject representing the message to be sent.</p>\n<p>The keyword argument <code class=\"docutils literal notranslate\">policy</code> allows specifying the set of rules for\nupdating and serializing the representation of the message. It must be\nan <a class=\"reference external\" href=\"https://docs.python.org/3/library/email.policy.html#module-email.policy\" title=\"(in Python v3.14)\"><code class=\"xref py py-mod docutils literal notranslate\">email.policy.Policy</code></a> object. Defaults to\n<a class=\"reference external\" href=\"https://docs.python.org/3/library/email.policy.html#email.policy.default\" title=\"(in Python v3.14)\"><code class=\"xref py py-data docutils literal notranslate\">email.policy.default</code></a>. In certain cases you may want to use\n<a class=\"reference external\" href=\"https://docs.python.org/3/library/email.policy.html#email.policy.SMTP\" title=\"(in Python v3.14)\"><code class=\"xref py py-data docutils literal notranslate\">SMTP</code></a>, <a class=\"reference external\" href=\"https://docs.python.org/3/library/email.policy.html#email.policy.SMTPUTF8\" title=\"(in Python v3.14)\"><code class=\"xref py py-data docutils literal notranslate\">SMTPUTF8</code></a> or a custom\npolicy. For example, the <a class=\"reference internal\" href=\"#topic-email-smtp-backend\"><span class=\"std std-ref\">SMTP email backend</span></a> uses the <a class=\"reference external\" href=\"https://docs.python.org/3/library/email.policy.html#email.policy.SMTP\" title=\"(in Python v3.14)\"><code class=\"xref py py-data docutils literal notranslate\">SMTP</code></a> policy\nto ensure <code class=\"docutils literal notranslate\">\\r\\n</code> line endings as required by the SMTP protocol.</p>\n<p>If you ever need to extend Django's <a class=\"reference internal\" href=\"#django.core.mail.EmailMessage\" title=\"django.core.mail.EmailMessage\"><code class=\"xref py py-class docutils literal notranslate\">EmailMessage</code></a> class,\nyou'll probably want to override this method to put the content you\nwant into the Python EmailMessage object.</p>\n<aside class=\"version-note version-changed\" data-version=\"6.0\" role=\"note\">\n<p class=\"version-note-title\">Changed in Django 6.0</p><p>The <code class=\"docutils literal notranslate\">policy</code> keyword argument was added and the return type was\nupdated to an instance of <a class=\"reference external\" href=\"https://docs.python.org/3/library/email.message.html#email.message.EmailMessage\" title=\"(in Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">EmailMessage</code></a>.</p>\n</aside>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.core.mail.EmailMessage.recipients\">\n<span class=\"sig-name descname\">recipients</span><span class=\"sig-paren\">(</span><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.core.mail.EmailMessage.recipients\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Returns a list of all the recipients of the message, whether they're\nrecorded in the <code class=\"docutils literal notranslate\">to</code>, <code class=\"docutils literal notranslate\">cc</code> or <code class=\"docutils literal notranslate\">bcc</code> attributes. This is another\nmethod you might need to override when subclassing, because the SMTP\nserver needs to be told the full list of recipients when the message\nis sent. If you add another way to specify recipients in your class,\nthey need to be returned from this method as well.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.core.mail.EmailMessage.attach\">\n<span class=\"sig-name descname\">attach</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">filename</em>, <em class=\"sig-param\">content</em>, <em class=\"sig-param\">mimetype</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.core.mail.EmailMessage.attach\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dt class=\"sig sig-object py\">\n<span class=\"sig-name descname\">attach</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">mimepart</em><span class=\"sig-paren\">)</span></dt>\n<dd><p>Creates a new attachment and adds it to the message. There are two ways\nto call <code class=\"xref py py-meth docutils literal notranslate\">attach()</code>:</p>\n<ul>\n<li><p>You can pass it three arguments: <code class=\"docutils literal notranslate\">filename</code>, <code class=\"docutils literal notranslate\">content</code> and\n<code class=\"docutils literal notranslate\">mimetype</code>. <code class=\"docutils literal notranslate\">filename</code> is the name of the file attachment as it\nwill appear in the email, <code class=\"docutils literal notranslate\">content</code> is the data that will be\ncontained inside the attachment and <code class=\"docutils literal notranslate\">mimetype</code> is the optional MIME\ntype for the attachment. If you omit <code class=\"docutils literal notranslate\">mimetype</code>, the MIME content\ntype will be guessed from the filename of the attachment.</p>\n<p>例:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>message<span class=\"o\">.</span>attach<span class=\"p\">(</span><span class=\"s2\">&quot;design.png&quot;</span><span class=\"p\">,</span> img_data<span class=\"p\">,</span> <span class=\"s2\">&quot;image/png&quot;</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>If you specify a <code class=\"docutils literal notranslate\">mimetype</code> of <em class=\"mimetype\">message/rfc822</em>,\n<code class=\"docutils literal notranslate\">content</code> can be a <a class=\"reference internal\" href=\"#django.core.mail.EmailMessage\" title=\"django.core.mail.EmailMessage\"><code class=\"xref py py-class docutils literal notranslate\">django.core.mail.EmailMessage</code></a> or\nPython's <a class=\"reference external\" href=\"https://docs.python.org/3/library/email.message.html#email.message.EmailMessage\" title=\"(in Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">email.message.EmailMessage</code></a> or\n<a class=\"reference external\" href=\"https://docs.python.org/3/library/email.compat32-message.html#email.message.Message\" title=\"(in Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">email.message.Message</code></a>.</p>\n<p><em class=\"mimetype\">text/</em> で始まる <code class=\"docutils literal notranslate\">mimetype</code> では、コンテンツは文字列であることが期待されます。バイナリデータはUTF-8でデコードされ、それが失敗した場合、MIMEタイプは <em class=\"mimetype\">application/octet-stream</em> に変更され、データは変更されずに添付されます。</p>\n</li>\n<li><p>Or for attachments requiring additional headers or parameters, you\ncan pass <code class=\"xref py py-meth docutils literal notranslate\">attach()</code> a single Python\n<a class=\"reference external\" href=\"https://docs.python.org/3/library/email.message.html#email.message.MIMEPart\" title=\"(in Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">MIMEPart</code></a> object. This will be attached\ndirectly to the resulting message. For example, to attach an inline\nimage with a <em class=\"mailheader\">Content-ID</em>:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">import</span> <span class=\"nn\">email.utils</span>\n<span class=\"kn\">from</span> <span class=\"nn\">email.message</span> <span class=\"kn\">import</span> MIMEPart\n<span class=\"kn\">from</span> <span class=\"nn\">django.core.mail</span> <span class=\"kn\">import</span> EmailMultiAlternatives\n\nmessage <span class=\"o\">=</span> EmailMultiAlternatives<span class=\"p\">(</span><span class=\"o\">...</span><span class=\"p\">)</span>\nimage_data_bytes <span class=\"o\">=</span> <span class=\"o\">...</span>  <span class=\"c1\"># Load image as bytes</span>\n\n<span class=\"c1\"># Create a random Content-ID, including angle brackets</span>\ncid <span class=\"o\">=</span> email<span class=\"o\">.</span>utils<span class=\"o\">.</span>make_msgid<span class=\"p\">()</span>\ninline_image <span class=\"o\">=</span> email<span class=\"o\">.</span>message<span class=\"o\">.</span>MIMEPart<span class=\"p\">()</span>\ninline_image<span class=\"o\">.</span>set_content<span class=\"p\">(</span>\n    image_data_bytes<span class=\"p\">,</span>\n    maintype<span class=\"o\">=</span><span class=\"s2\">&quot;image&quot;</span><span class=\"p\">,</span>\n    subtype<span class=\"o\">=</span><span class=\"s2\">&quot;png&quot;</span><span class=\"p\">,</span>  <span class=\"c1\"># or &quot;jpeg&quot;, etc. depending on the image type</span>\n    disposition<span class=\"o\">=</span><span class=\"s2\">&quot;inline&quot;</span><span class=\"p\">,</span>\n    cid<span class=\"o\">=</span>cid<span class=\"p\">,</span>\n<span class=\"p\">)</span>\nmessage<span class=\"o\">.</span>attach<span class=\"p\">(</span>inline_image<span class=\"p\">)</span>\n<span class=\"c1\"># Refer to Content-ID in HTML without angle brackets</span>\nmessage<span class=\"o\">.</span>attach_alternative<span class=\"p\">(</span><span class=\"sa\">f</span><span class=\"s1\">&#39;… &lt;img src=&quot;cid:</span><span class=\"si\">{</span>cid<span class=\"p\">[</span><span class=\"mi\">1</span><span class=\"p\">:</span><span class=\"o\">-</span><span class=\"mi\">1</span><span class=\"p\">]</span><span class=\"si\">}</span><span class=\"s1\">&quot;&gt; …&#39;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;text/html&quot;</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>Python's <a class=\"reference external\" href=\"https://docs.python.org/3/library/email.contentmanager.html#email.contentmanager.set_content\" title=\"(in Python v3.14)\"><code class=\"xref py py-meth docutils literal notranslate\">email.contentmanager.set_content()</code></a> documentation\ndescribes the supported arguments for <code class=\"docutils literal notranslate\">MIMEPart.set_content()</code>.</p>\n<aside class=\"version-note version-changed\" data-version=\"6.0\" role=\"note\">\n<p class=\"version-note-title\">Changed in Django 6.0</p><p>Support for <a class=\"reference external\" href=\"https://docs.python.org/3/library/email.message.html#email.message.MIMEPart\" title=\"(in Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">MIMEPart</code></a> attachments was\nadded.</p>\n</aside>\n<aside class=\"version-note version-deprecated\" data-version=\"6.0\" role=\"note\">\n<p class=\"version-note-title\">Deprecated since Django 6.0</p><p><span class=\"versionmodified deprecated\">バージョン 6.0 で非推奨: </span>Support for <a class=\"reference external\" href=\"https://docs.python.org/3/library/email.mime.html#email.mime.base.MIMEBase\" title=\"(in Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">email.mime.base.MIMEBase</code></a> attachments is\ndeprecated. Use <a class=\"reference external\" href=\"https://docs.python.org/3/library/email.message.html#email.message.MIMEPart\" title=\"(in Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">MIMEPart</code></a> instead.</p>\n</aside>\n</li>\n</ul>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.core.mail.EmailMessage.attach_file\">\n<span class=\"sig-name descname\">attach_file</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">path</em>, <em class=\"sig-param\">mimetype<span class=\"o\">=</span><span class=\"default_value\">None</span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.core.mail.EmailMessage.attach_file\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Creates a new attachment using a file from your filesystem. Call it\nwith the path of the file to attach and, optionally, the MIME type to\nuse for the attachment. If the MIME type is omitted, it will be guessed\nfrom the filename. You can use it like this:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>message<span class=\"o\">.</span>attach_file<span class=\"p\">(</span><span class=\"s2\">&quot;/images/weather_map.png&quot;</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>For MIME types starting with <em class=\"mimetype\">text/</em>, binary data is handled\nas in <a class=\"reference internal\" href=\"#django.core.mail.EmailMessage.attach\" title=\"django.core.mail.EmailMessage.attach\"><code class=\"xref py py-meth docutils literal notranslate\">attach()</code></a>.</p>\n</dd></dl>\n\n</dd></dl>\n\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.core.mail.EmailAttachment\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">EmailAttachment</span><a class=\"heading-anchor\" href=\"#django.core.mail.EmailAttachment\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>メールに添付するファイルを保持するための名前付きタプルです。</p>\n<p>この名前付きタプルは、下記のインデックスを持ちます：</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\">filename</code></p></li>\n<li><p><code class=\"docutils literal notranslate\">content</code></p></li>\n<li><p><code class=\"docutils literal notranslate\">mimetype</code></p></li>\n</ul>\n</dd></dl>\n\n<section id=\"sending-alternative-content-types\">\n<h4>代替のコンテンツタイプを送信する<a class=\"heading-anchor\" href=\"#sending-alternative-content-types\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<section id=\"sending-multiple-content-versions\">\n<h5>複数のバージョンを持つコンテンツを送る<a class=\"heading-anchor\" href=\"#sending-multiple-content-versions\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h5>\n<p>It can be useful to include multiple versions of the content in an email; the\nclassic example is to send both text and HTML versions of a message. With\nDjango's email library, you can do this using the\n<a class=\"reference internal\" href=\"#django.core.mail.EmailMultiAlternatives\" title=\"django.core.mail.EmailMultiAlternatives\"><code class=\"xref py py-class docutils literal notranslate\">EmailMultiAlternatives</code></a> class.</p>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.core.mail.EmailMultiAlternatives\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">EmailMultiAlternatives</span><a class=\"heading-anchor\" href=\"#django.core.mail.EmailMultiAlternatives\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p><a class=\"reference internal\" href=\"#django.core.mail.EmailMultiAlternatives.attach_alternative\" title=\"django.core.mail.EmailMultiAlternatives.attach_alternative\"><code class=\"xref py py-meth docutils literal notranslate\">attach_alternative()</code></a> メソッドを通じて、メール本文の別バージョンを追加できるようにした <a class=\"reference internal\" href=\"#django.core.mail.EmailMessage\" title=\"django.core.mail.EmailMessage\"><code class=\"xref py py-class docutils literal notranslate\">EmailMessage</code></a> のサブクラスです。このクラスは <a class=\"reference internal\" href=\"#django.core.mail.EmailMessage\" title=\"django.core.mail.EmailMessage\"><code class=\"xref py py-class docutils literal notranslate\">EmailMessage</code></a> からすべてのメソッド（初期化メソッドも含む）をそのまま継承しています。</p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.core.mail.EmailMultiAlternatives.alternatives\">\n<span class=\"sig-name descname\">alternatives</span><a class=\"heading-anchor\" href=\"#django.core.mail.EmailMultiAlternatives.alternatives\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>A list of <a class=\"reference internal\" href=\"#django.core.mail.EmailAlternative\" title=\"django.core.mail.EmailAlternative\"><code class=\"xref py py-class docutils literal notranslate\">EmailAlternative</code></a> named tuples.\nThis is particularly useful in tests:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"bp\">self</span><span class=\"o\">.</span>assertEqual<span class=\"p\">(</span><span class=\"nb\">len</span><span class=\"p\">(</span>msg<span class=\"o\">.</span>alternatives<span class=\"p\">),</span> <span class=\"mi\">1</span><span class=\"p\">)</span>\n<span class=\"bp\">self</span><span class=\"o\">.</span>assertEqual<span class=\"p\">(</span>msg<span class=\"o\">.</span>alternatives<span class=\"p\">[</span><span class=\"mi\">0</span><span class=\"p\">]</span><span class=\"o\">.</span>content<span class=\"p\">,</span> html_content<span class=\"p\">)</span>\n<span class=\"bp\">self</span><span class=\"o\">.</span>assertEqual<span class=\"p\">(</span>msg<span class=\"o\">.</span>alternatives<span class=\"p\">[</span><span class=\"mi\">0</span><span class=\"p\">]</span><span class=\"o\">.</span>mimetype<span class=\"p\">,</span> <span class=\"s2\">&quot;text/html&quot;</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>代替コンテンツは、 <a class=\"reference internal\" href=\"#django.core.mail.EmailMultiAlternatives.attach_alternative\" title=\"django.core.mail.EmailMultiAlternatives.attach_alternative\"><code class=\"xref py py-meth docutils literal notranslate\">attach_alternative()</code></a> メソッドを使って追加するか、コンストラクタに渡して指定する必要があります。</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.core.mail.EmailMultiAlternatives.attach_alternative\">\n<span class=\"sig-name descname\">attach_alternative</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">content</em>, <em class=\"sig-param\">mimetype</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.core.mail.EmailMultiAlternatives.attach_alternative\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>メール内にメッセージ本文の代替の表現を添付します。</p>\n<p>例えば、テキスト版とHTML版を組み合わせて送信する場合、次のようにします。</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.core.mail</span> <span class=\"kn\">import</span> EmailMultiAlternatives\n\nsubject <span class=\"o\">=</span> <span class=\"s2\">&quot;hello&quot;</span>\nfrom_email <span class=\"o\">=</span> <span class=\"s2\">&quot;from@example.com&quot;</span>\nto <span class=\"o\">=</span> <span class=\"s2\">&quot;to@example.com&quot;</span>\ntext_content <span class=\"o\">=</span> <span class=\"s2\">&quot;This is an important message.&quot;</span>\nhtml_content <span class=\"o\">=</span> <span class=\"s2\">&quot;&lt;p&gt;This is an &lt;strong&gt;important&lt;/strong&gt; message.&lt;/p&gt;&quot;</span>\nmsg <span class=\"o\">=</span> EmailMultiAlternatives<span class=\"p\">(</span>subject<span class=\"p\">,</span> text_content<span class=\"p\">,</span> from_email<span class=\"p\">,</span> <span class=\"p\">[</span>to<span class=\"p\">])</span>\nmsg<span class=\"o\">.</span>attach_alternative<span class=\"p\">(</span>html_content<span class=\"p\">,</span> <span class=\"s2\">&quot;text/html&quot;</span><span class=\"p\">)</span>\nmsg<span class=\"o\">.</span>send<span class=\"p\">()</span>\n</code></pre></div>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.core.mail.EmailMultiAlternatives.body_contains\">\n<span class=\"sig-name descname\">body_contains</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">text</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.core.mail.EmailMultiAlternatives.body_contains\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>指定された <code class=\"docutils literal notranslate\">text</code> が、メールの <code class=\"docutils literal notranslate\">body</code> およびすべての <code class=\"docutils literal notranslate\">text/*</code> MIME タイプの代替コンテンツに含まれているかどうかを示す真偽値を返します。</p>\n<p>これはメールのテストのときに便利です。たとえば：</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"k\">def</span> <span class=\"nf\">test_contains_email_content</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n    subject <span class=\"o\">=</span> <span class=\"s2\">&quot;Hello World&quot;</span>\n    from_email <span class=\"o\">=</span> <span class=\"s2\">&quot;from@example.com&quot;</span>\n    to <span class=\"o\">=</span> <span class=\"s2\">&quot;to@example.com&quot;</span>\n    msg <span class=\"o\">=</span> EmailMultiAlternatives<span class=\"p\">(</span>subject<span class=\"p\">,</span> <span class=\"s2\">&quot;I am content.&quot;</span><span class=\"p\">,</span> from_email<span class=\"p\">,</span> <span class=\"p\">[</span>to<span class=\"p\">])</span>\n    msg<span class=\"o\">.</span>attach_alternative<span class=\"p\">(</span><span class=\"s2\">&quot;&lt;p&gt;I am content.&lt;/p&gt;&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;text/html&quot;</span><span class=\"p\">)</span>\n\n    <span class=\"bp\">self</span><span class=\"o\">.</span>assertIs<span class=\"p\">(</span>msg<span class=\"o\">.</span>body_contains<span class=\"p\">(</span><span class=\"s2\">&quot;I am content&quot;</span><span class=\"p\">),</span> <span class=\"kc\">True</span><span class=\"p\">)</span>\n    <span class=\"bp\">self</span><span class=\"o\">.</span>assertIs<span class=\"p\">(</span>msg<span class=\"o\">.</span>body_contains<span class=\"p\">(</span><span class=\"s2\">&quot;&lt;p&gt;I am content.&lt;/p&gt;&quot;</span><span class=\"p\">),</span> <span class=\"kc\">False</span><span class=\"p\">)</span>\n</code></pre></div>\n</dd></dl>\n\n</dd></dl>\n\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.core.mail.EmailAlternative\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-name descname\">EmailAlternative</span><a class=\"heading-anchor\" href=\"#django.core.mail.EmailAlternative\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>メールコンテンツの別バージョンを保持するための名前付きタプルです。</p>\n<p>この名前付きタプルは、下記のインデックスを持ちます：</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\">content</code></p></li>\n<li><p><code class=\"docutils literal notranslate\">mimetype</code></p></li>\n</ul>\n</dd></dl>\n\n</section>\n<section id=\"updating-the-default-content-type\">\n<h5>デフォルトのコンテンツタイプを変更する<a class=\"heading-anchor\" href=\"#updating-the-default-content-type\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h5>\n<p>By default, the MIME type of the <code class=\"docutils literal notranslate\">body</code> parameter in an <a class=\"reference internal\" href=\"#django.core.mail.EmailMessage\" title=\"django.core.mail.EmailMessage\"><code class=\"xref py py-class docutils literal notranslate\">EmailMessage</code></a>\nis <code class=\"docutils literal notranslate\">&quot;text/plain&quot;</code>. It is good practice to leave this alone, because it\nguarantees that any recipient will be able to read the email, regardless of\ntheir mail client. However, if you are confident that your recipients can\nhandle an alternative content type, you can use the <code class=\"docutils literal notranslate\">content_subtype</code>\nattribute on the <a class=\"reference internal\" href=\"#django.core.mail.EmailMessage\" title=\"django.core.mail.EmailMessage\"><code class=\"xref py py-class docutils literal notranslate\">EmailMessage</code></a> class to change the main content type.\nThe major type will always be <code class=\"docutils literal notranslate\">&quot;text&quot;</code>, but you can change the subtype. For\nexample:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>msg <span class=\"o\">=</span> EmailMessage<span class=\"p\">(</span>subject<span class=\"p\">,</span> html_content<span class=\"p\">,</span> from_email<span class=\"p\">,</span> <span class=\"p\">[</span>to<span class=\"p\">])</span>\nmsg<span class=\"o\">.</span>content_subtype <span class=\"o\">=</span> <span class=\"s2\">&quot;html&quot;</span>  <span class=\"c1\"># Main content is now text/html</span>\nmsg<span class=\"o\">.</span>send<span class=\"p\">()</span>\n</code></pre></div>\n</section>\n</section>\n</section>\n<section id=\"safely-sending-email\">\n<h3>Safely sending email<a class=\"heading-anchor\" href=\"#safely-sending-email\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Any public website that can send email will eventually be targeted by attempts\nto abuse it for spam, phishing, or other malicious content. While a complete\ndiscussion of vulnerabilities in sending email is beyond the scope of Django's\ndocumentation, there are many references available on the web. Two good\nstarting points are:</p>\n<ul class=\"simple\">\n<li><p>Princeton University's guidance on <a class=\"reference external\" href=\"https://sitebuilder.princeton.edu/site-administration/spam\">preventing email abuse in web forms</a>.\nAlthough this is an internal reference for users of Princeton's Drupal Site\nBuilder, nearly all of its advice applies equally to sites built with Django\n(or any web framework).</p></li>\n<li><p>OWASP's <a class=\"reference external\" href=\"https://cheatsheetseries.owasp.org/cheatsheets/Email_Validation_and_Verification_Cheat_Sheet.html\">Email Validation and Verification in Identity Systems Cheat Sheet</a>.\nThis primarily covers using email in authentication contexts. While many of\nits recommendations are handled by <a class=\"reference internal\" href=\"/ja/6.1/topics/auth/#module-django.contrib.auth\" title=\"django.contrib.auth: Django's authentication framework.\"><code class=\"xref py py-mod docutils literal notranslate\">django.contrib.auth</code></a> and other\nDjango features, items like rate limiting and securing email change workflows\nare the developer's responsibility.</p></li>\n</ul>\n<p>Thinking through how email might be abused (and taking steps to mitigate it) is\nespecially important if your site can send to unverified addresses. Features\nlike newsletter sign-up, contact forms that cc or auto-reply to the sender, and\n&quot;share this page&quot; can be attractive targets.</p>\n<section id=\"formatting-email-addresses\">\n<span id=\"formatting-addresses\"></span><h4>Formatting email addresses<a class=\"heading-anchor\" href=\"#formatting-email-addresses\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Email addresses allow a &quot;friendly&quot; display name alongside the <code class=\"docutils literal notranslate\">user&#64;domain</code>\naddress. For example, you could include your company name in the\n<a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-DEFAULT_FROM_EMAIL\"><code class=\"xref std std-setting docutils literal notranslate\">DEFAULT_FROM_EMAIL</code></a> setting:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>DEFAULT_FROM_EMAIL <span class=\"o\">=</span> <span class=\"s1\">&#39;&quot;Example, Inc.&quot; &lt;contact@example.com&gt;&#39;</span>\n</code></pre></div>\n<p>The double quotes around <code class=\"docutils literal notranslate\">&quot;Example, Inc.&quot;</code> are needed so the comma isn't read\nas separating two different addresses. A fixed address, written out by hand as\nin the example above, is safe, but composing one from variable parts\n(especially untrusted input) needs more care.</p>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">警告</p>\n<p>Never use string formatting to build an email address from variable parts.\nFor example, <code class=\"docutils literal notranslate\">f'&quot;{name}&quot; &lt;{email}&gt;'</code> is <strong>unsafe</strong>.</p>\n</aside>\n<p>Email address headers have complex syntax rules (much like HTML or SQL), so\nconstructing them by combining strings creates an injection vulnerability. Even\nif you've <a class=\"reference internal\" href=\"/ja/6.1/ref/validators/#django.core.validators.EmailValidator\" title=\"django.core.validators.EmailValidator\"><code class=\"xref py py-class docutils literal notranslate\">validated</code></a> the format of <code class=\"docutils literal notranslate\">email</code>, an\nattacker could exploit the <code class=\"docutils literal notranslate\">name</code> portion to inject additional addresses.</p>\n<p>To avoid this, always use a well-tested library specifically meant to format\nemail addresses, like Python's <a class=\"reference external\" href=\"https://docs.python.org/3/library/email.headerregistry.html#email.headerregistry.Address\" title=\"(in Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">email.headerregistry.Address</code></a> class (the\nreplacement for the legacy <a class=\"reference external\" href=\"https://docs.python.org/3/library/email.utils.html#email.utils.formataddr\" title=\"(in Python v3.14)\"><code class=\"xref py py-func docutils literal notranslate\">formataddr()</code></a> function, which does\nnot support internationalized domain names).</p>\n<p>For example, to include a user's full name when sending them email (where\n<code class=\"docutils literal notranslate\">user</code> is an instance of the default <a class=\"reference internal\" href=\"/ja/6.1/ref/contrib/auth/#django.contrib.auth.models.User\" title=\"django.contrib.auth.models.User\"><code class=\"xref py py-class docutils literal notranslate\">User</code></a> model):</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.core.mail</span> <span class=\"kn\">import</span> send_mail\n<span class=\"kn\">from</span> <span class=\"nn\">email.headerregistry</span> <span class=\"kn\">import</span> Address\n\n\n<span class=\"k\">def</span> <span class=\"nf\">send_mail_to_user</span><span class=\"p\">(</span>user<span class=\"p\">,</span> subject<span class=\"p\">,</span> body<span class=\"p\">,</span> from_email<span class=\"o\">=</span><span class=\"kc\">None</span><span class=\"p\">):</span>\n    <span class=\"c1\"># Safely create an email address with the user&#39;s name.</span>\n    <span class=\"c1\"># (addr_spec is the technical term for the user@domain address.)</span>\n    address <span class=\"o\">=</span> Address<span class=\"p\">(</span>\n        display_name<span class=\"o\">=</span>user<span class=\"o\">.</span>get_full_name<span class=\"p\">(),</span>\n        addr_spec<span class=\"o\">=</span>user<span class=\"o\">.</span>email<span class=\"p\">,</span>\n    <span class=\"p\">)</span>\n    send_mail<span class=\"p\">(</span>subject<span class=\"p\">,</span> body<span class=\"p\">,</span> from_email<span class=\"p\">,</span> <span class=\"p\">[</span>address<span class=\"p\">])</span>\n</code></pre></div>\n<p>Django's built-in email backends support using\n<a class=\"reference external\" href=\"https://docs.python.org/3/library/email.headerregistry.html#email.headerregistry.Address\" title=\"(in Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">Address</code></a> objects directly in any address field,\nas shown here. So do many custom and third-party email backends. But if this\ncauses a <code class=\"docutils literal notranslate\">TypeError</code> or other problem with a particular backend, use\n<code class=\"docutils literal notranslate\">str(address)</code> to convert the object to a safe, properly formatted string.</p>\n</section>\n<section id=\"preventing-header-injection\">\n<h4>ヘッダインジェクションを防止する<a class=\"heading-anchor\" href=\"#preventing-header-injection\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p><a class=\"reference external\" href=\"https://en.wikipedia.org/wiki/Email_injection\">Email header injection</a> is a security exploit in which an attacker\nmanipulates email headers to change the intended sender or recipients, subject,\nor potentially even the entire visible message body.</p>\n<p>One type of header injection exploits address header syntax. You are\nresponsible for preventing this when constructing email addresses from\nuser-supplied input, as described in <a class=\"reference internal\" href=\"#formatting-addresses\"><span class=\"std std-ref\">Formatting email addresses</span></a> above.</p>\n<p>Another (perhaps better understood) attack, CRLF injection, uses carriage\nreturn and line feed characters to insert additional headers into the email.\nDjango prevents this by raising a <a class=\"reference external\" href=\"https://docs.python.org/3/library/exceptions.html#ValueError\" title=\"(in Python v3.14)\"><code class=\"xref py py-exc docutils literal notranslate\">ValueError</code></a> if those characters appear\nin any header field when trying to send the message.</p>\n<aside class=\"version-note version-changed\" data-version=\"6.0\" role=\"note\">\n<p class=\"version-note-title\">Changed in Django 6.0</p><p>Older versions raised <code class=\"docutils literal notranslate\">django.core.mail.BadHeaderError</code> for some\ninvalid headers. This has been replaced with <code class=\"xref py py-exc docutils literal notranslate\">ValueError</code>.</p>\n</aside>\n<p>Django's CRLF protection relies on using Python's modern\n<a class=\"reference external\" href=\"https://docs.python.org/3/library/email.policy.html#email.policy.EmailPolicy\" title=\"(in Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">EmailPolicy</code></a> in Django's <a class=\"reference internal\" href=\"#django.core.mail.EmailMessage.message\" title=\"django.core.mail.EmailMessage.message\"><code class=\"xref py py-meth docutils literal notranslate\">EmailMessage.message()</code></a>.\nCustom email backends that don't call that function, or that call it with the\nlegacy <a class=\"reference external\" href=\"https://docs.python.org/3/library/email.policy.html#email.policy.compat32\" title=\"(in Python v3.14)\"><code class=\"xref py py-data docutils literal notranslate\">compat32</code></a> policy, are responsible for implementing\ntheir own CRLF injection prevention.</p>\n</section>\n</section>\n<section id=\"sending-many-messages-efficiently\">\n<span id=\"topics-sending-multiple-emails\"></span><h3>Sending many messages efficiently<a class=\"heading-anchor\" href=\"#sending-many-messages-efficiently\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>SMTP コネクション (またはその他のネットワークコネクション) の確立とクローズは、負荷の高い処理です。 送信するメールがたくさんある場合は、メールを送信するたびにコネクションの生成と破棄を繰り返すのではなく、SMTP コネクションを再利用する方が効率的です。</p>\n<p>There are two ways to tell an email backend to reuse a connection. Both involve\nobtaining an email backend instance from <a class=\"reference internal\" href=\"#django.core.mail.mailers\" title=\"django.core.mail.mailers\"><code class=\"xref py py-data docutils literal notranslate\">mail.mailers</code></a> and using the\n<a class=\"reference internal\" href=\"#topic-email-backend-api\"><span class=\"std std-ref\">backend's API</span></a>.</p>\n<p>The first approach is to use the backend's <code class=\"docutils literal notranslate\">send_messages()</code> method. This\ntakes a list of <a class=\"reference internal\" href=\"#django.core.mail.EmailMessage\" title=\"django.core.mail.EmailMessage\"><code class=\"xref py py-class docutils literal notranslate\">EmailMessage</code></a> (or subclass) instances, and sends them\nall using that single connection.</p>\n<p>For example, if you have a function called <code class=\"docutils literal notranslate\">get_notification_emails()</code> that\nreturns a list of <a class=\"reference internal\" href=\"#django.core.mail.EmailMessage\" title=\"django.core.mail.EmailMessage\"><code class=\"xref py py-class docutils literal notranslate\">EmailMessage</code></a> objects representing some periodic\nemail you wish to send out, you could send these emails using a single call to\n<code class=\"docutils literal notranslate\">send_messages()</code>:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.core</span> <span class=\"kn\">import</span> mail\n\nemail_list <span class=\"o\">=</span> get_notification_emails<span class=\"p\">()</span>\n<span class=\"c1\"># Use the default mailer. You could substitute</span>\n<span class=\"c1\"># mail.mailers[&quot;alias&quot;] for a specific mailer.</span>\nbackend <span class=\"o\">=</span> mail<span class=\"o\">.</span>mailers<span class=\"o\">.</span>default\nbackend<span class=\"o\">.</span>send_messages<span class=\"p\">(</span>email_list<span class=\"p\">)</span>\n</code></pre></div>\n<p>In this example, the call to <code class=\"docutils literal notranslate\">send_messages()</code> opens a connection on the\nbackend, sends the list of messages, and then closes the connection again.\n(This is how <a class=\"reference internal\" href=\"#django.core.mail.send_mass_mail\" title=\"django.core.mail.send_mass_mail\"><code class=\"xref py py-func docutils literal notranslate\">send_mass_mail()</code></a> is implemented.)</p>\n<p>The second approach is to use the <code class=\"docutils literal notranslate\">open()</code> and <code class=\"docutils literal notranslate\">close()</code> methods on the\nemail backend to manually control the connection. <code class=\"docutils literal notranslate\">send_messages()</code> will not\nopen or close the connection if it is already open, so if you\nmanually open the connection, you can control when it is closed. For example:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.core</span> <span class=\"kn\">import</span> mail\n\n<span class=\"c1\"># Use the &quot;notifications&quot; mailer configuration.</span>\nbackend <span class=\"o\">=</span> mail<span class=\"o\">.</span>mailers<span class=\"p\">[</span><span class=\"s2\">&quot;notifications&quot;</span><span class=\"p\">]</span>\n\n<span class=\"c1\"># Manually open the connection.</span>\nbackend<span class=\"o\">.</span>open<span class=\"p\">()</span>\n\n<span class=\"c1\"># Construct an email message. (Passing None as the third argument</span>\n<span class=\"c1\"># uses settings.DEFAULT_FROM_EMAIL as the &quot;From:&quot; address.)</span>\nemail1 <span class=\"o\">=</span> mail<span class=\"o\">.</span>EmailMessage<span class=\"p\">(</span><span class=\"s2\">&quot;Hi&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Message&quot;</span><span class=\"p\">,</span> <span class=\"kc\">None</span><span class=\"p\">,</span> <span class=\"p\">[</span><span class=\"s2\">&quot;to1@example.com&quot;</span><span class=\"p\">])</span>\n<span class=\"c1\"># Send the email. The connection was already open, so send_messages()</span>\n<span class=\"c1\"># leaves it open after sending.</span>\nbackend<span class=\"o\">.</span>send_messages<span class=\"p\">([</span>email1<span class=\"p\">])</span>\n\n<span class=\"c1\"># Construct and send two more messages. The connection is still open.</span>\nemail2 <span class=\"o\">=</span> mail<span class=\"o\">.</span>EmailMessage<span class=\"p\">(</span><span class=\"s2\">&quot;Hi&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Message&quot;</span><span class=\"p\">,</span> <span class=\"kc\">None</span><span class=\"p\">,</span> <span class=\"p\">[</span><span class=\"s2\">&quot;to2@example.com&quot;</span><span class=\"p\">])</span>\nemail3 <span class=\"o\">=</span> mail<span class=\"o\">.</span>EmailMessage<span class=\"p\">(</span><span class=\"s2\">&quot;Hi&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Message&quot;</span><span class=\"p\">,</span> <span class=\"kc\">None</span><span class=\"p\">,</span> <span class=\"p\">[</span><span class=\"s2\">&quot;to3@example.com&quot;</span><span class=\"p\">])</span>\nbackend<span class=\"o\">.</span>send_messages<span class=\"p\">([</span>email2<span class=\"p\">,</span> email3<span class=\"p\">])</span>\n\n<span class=\"c1\"># Because we opened it, we need to manually close the connection.</span>\nbackend<span class=\"o\">.</span>close<span class=\"p\">()</span>\n</code></pre></div>\n<p>When you manually open a backend's connection, you are responsible for ensuring\nit gets closed. The example above actually has a bug: if an exception occurs\nwhile sending the messages, the connection will not be closed. This can be\nfixed with a <code class=\"docutils literal notranslate\">try</code>-<code class=\"docutils literal notranslate\">finally</code> statement, but using the backend instance as a\ncontext manager is preferable, as it automatically calls <code class=\"docutils literal notranslate\">open()</code> and\n<code class=\"docutils literal notranslate\">close()</code> as needed.</p>\n<p>This is equivalent to the previous example, but uses the backend as a\n<a class=\"reference external\" href=\"https://docs.python.org/3/reference/datamodel.html#context-managers\" title=\"(in Python v3.14)\"><span class=\"xref std std-ref\">context manager</span></a> to avoid leaving the connection open\non errors:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.core</span> <span class=\"kn\">import</span> mail\n\n<span class=\"c1\"># Use mail.mailers[...] as a context manager.</span>\n<span class=\"k\">with</span> mail<span class=\"o\">.</span>mailers<span class=\"p\">[</span><span class=\"s2\">&quot;notifications&quot;</span><span class=\"p\">]</span> <span class=\"k\">as</span> backend<span class=\"p\">:</span>\n    <span class=\"c1\"># The backend connection is automatically opened inside the context.</span>\n    email1 <span class=\"o\">=</span> mail<span class=\"o\">.</span>EmailMessage<span class=\"p\">(</span><span class=\"s2\">&quot;Hi&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Message&quot;</span><span class=\"p\">,</span> <span class=\"kc\">None</span><span class=\"p\">,</span> <span class=\"p\">[</span><span class=\"s2\">&quot;to1@example.com&quot;</span><span class=\"p\">])</span>\n    backend<span class=\"o\">.</span>send_messages<span class=\"p\">([</span>email1<span class=\"p\">])</span>\n\n    <span class=\"c1\"># The connection is still open, and is reused for the second send.</span>\n    email2 <span class=\"o\">=</span> mail<span class=\"o\">.</span>EmailMessage<span class=\"p\">(</span><span class=\"s2\">&quot;Hi&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Message&quot;</span><span class=\"p\">,</span> <span class=\"kc\">None</span><span class=\"p\">,</span> <span class=\"p\">[</span><span class=\"s2\">&quot;to2@example.com&quot;</span><span class=\"p\">])</span>\n    email3 <span class=\"o\">=</span> mail<span class=\"o\">.</span>EmailMessage<span class=\"p\">(</span><span class=\"s2\">&quot;Hi&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;Message&quot;</span><span class=\"p\">,</span> <span class=\"kc\">None</span><span class=\"p\">,</span> <span class=\"p\">[</span><span class=\"s2\">&quot;to3@example.com&quot;</span><span class=\"p\">])</span>\n    backend<span class=\"o\">.</span>send_messages<span class=\"p\">([</span>email2<span class=\"p\">,</span> email3<span class=\"p\">])</span>\n\n<span class=\"c1\"># After exiting the context (either normally or because of an error),</span>\n<span class=\"c1\"># the backend connection is automatically closed.</span>\n</code></pre></div>\n</section>\n</section>\n<section id=\"email-backends\">\n<span id=\"topic-email-backends\"></span><h2>メールのバックエンド<a class=\"heading-anchor\" href=\"#email-backends\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>実際のメール送信は、メールバックエンドによって処理されます。</p>\n<p>Django comes with several email backends. With the exception of the SMTP\nbackend, these are mainly useful during testing and development. If the\nbuilt-in backends don't meet your needs there are <a class=\"reference internal\" href=\"#topic-third-party-email-backends\"><span class=\"std std-ref\">third-party packages</span></a> available. You can also subclass one of the\nbuilt-in backends to change its behavior, or even <a class=\"reference internal\" href=\"#topic-custom-email-backend\"><span class=\"std std-ref\">write your own email\nbackend</span></a>.</p>\n<section id=\"smtp-backend\">\n<span id=\"topic-email-smtp-backend\"></span><h3>SMTP バックエンド<a class=\"heading-anchor\" href=\"#smtp-backend\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>The SMTP email backend connects to an SMTP server to send email. To use it, set\n<a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS-BACKEND\"><code class=\"xref std std-setting docutils literal notranslate\">BACKEND</code></a> to\n<code class=\"docutils literal notranslate\">&quot;django.core.mail.backends.smtp.EmailBackend&quot;</code>.</p>\n<p>The SMTP backend supports these <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\">OPTIONS</code></a>:</p>\n<ul>\n<li><p><code class=\"docutils literal notranslate\">&quot;host&quot;</code> (required): the SMTP server hostname or IP address.</p></li>\n<li><p><code class=\"docutils literal notranslate\">&quot;port&quot;</code>: the port number to connect to on the SMTP host. If omitted,\nuses the standard port for the connection protocol depending on the\n<code class=\"docutils literal notranslate\">&quot;use_tls&quot;</code> and <code class=\"docutils literal notranslate\">&quot;use_ssl&quot;</code> options: <code class=\"docutils literal notranslate\">587</code> for TLS, <code class=\"docutils literal notranslate\">465</code> for SSL,\nor <code class=\"docutils literal notranslate\">25</code> for an unsecured connection.</p></li>\n<li><p><code class=\"docutils literal notranslate\">&quot;username&quot;</code> and <code class=\"docutils literal notranslate\">&quot;password&quot;</code>: set these if your server requires SMTP\nauthentication (&quot;SMTP AUTH&quot; credentials, sometimes called SMTP login).</p>\n<p>Although the username is often an email address, it should not be confused\nwith default &quot;From:&quot; addresses. Those are defined by the\n<a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-DEFAULT_FROM_EMAIL\"><code class=\"xref std std-setting docutils literal notranslate\">DEFAULT_FROM_EMAIL</code></a> and <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-SERVER_EMAIL\"><code class=\"xref std std-setting docutils literal notranslate\">SERVER_EMAIL</code></a> settings.</p>\n</li>\n<li><p><code class=\"docutils literal notranslate\">&quot;use_tls&quot;</code> or <code class=\"docutils literal notranslate\">&quot;use_ssl&quot;</code>: set one of these options to <code class=\"docutils literal notranslate\">True</code> to\nconnect to the SMTP server using a secure protocol -- <code class=\"docutils literal notranslate\">&quot;use_tls&quot;</code> for\nexplicit TLS or <code class=\"docutils literal notranslate\">&quot;use_ssl&quot;</code> for SSL (implicit TLS).</p></li>\n<li><p><code class=\"docutils literal notranslate\">&quot;ssl_certfile&quot;</code> and <code class=\"docutils literal notranslate\">&quot;ssl_keyfile&quot;</code>: if the SMTP server's SSL/TLS\nconnection requires client certificate authentication, use these options to\nspecify the paths to a PEM-formatted certificate chain file and private key\nfile. (The key file can be omitted if the certificate file includes the\nprivate key.)</p>\n<p>These options are not intended for use with a private certificate authority\nor self-signed SMTP server certificate. See\n<a class=\"reference internal\" href=\"#topic-email-smtp-private-ca\"><span class=\"std std-ref\">Private and self-signed SMTP server certificates</span></a> below.</p>\n<p>Note that these options don't result in checking certificate validity. They\nare passed to the underlying SSL connection. Refer to the documentation of\nPython's <a class=\"reference external\" href=\"https://docs.python.org/3/library/ssl.html#ssl.SSLContext.wrap_socket\" title=\"(in Python v3.14)\"><code class=\"xref py py-meth docutils literal notranslate\">ssl.SSLContext.wrap_socket()</code></a> method for details on how the\ncertificate chain file and private key file are handled.</p>\n</li>\n<li><p><code class=\"docutils literal notranslate\">&quot;timeout&quot;</code>: the timeout (in seconds) for connecting to the SMTP server and\nother blocking operations. If not specified, the value is obtained from\n<a class=\"reference external\" href=\"https://docs.python.org/3/library/socket.html#socket.getdefaulttimeout\" title=\"(in Python v3.14)\"><code class=\"xref py py-func docutils literal notranslate\">socket.getdefaulttimeout()</code></a>, which defaults to no timeout (<code class=\"docutils literal notranslate\">None</code>)\nmeaning SMTP operations can block indefinitely.</p></li>\n<li><p><code class=\"docutils literal notranslate\">&quot;fail_silently&quot;</code>: set to <code class=\"docutils literal notranslate\">True</code> to ignore certain errors while sending\na message. All <a class=\"reference external\" href=\"https://docs.python.org/3/library/exceptions.html#OSError\" title=\"(in Python v3.14)\"><code class=\"xref py py-exc docutils literal notranslate\">OSError</code></a>s are ignored while opening the SMTP\nconnection, and <a class=\"reference external\" href=\"https://docs.python.org/3/library/smtplib.html#smtplib.SMTPException\" title=\"(in Python v3.14)\"><code class=\"xref py py-exc docutils literal notranslate\">smtplib.SMTPException</code></a> errors are ignored while\ncommunicating with the server. This will suppress both transient network\nglitches and also serious configuration problems. However, it does not ignore\n<em>all</em> errors, and problems with serializing the message will not fail\nsilently. (This option is available for backward compatibility but is not\nrecommended for typical use.)</p></li>\n</ul>\n<p>実装例:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>MAILERS <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;default&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;BACKEND&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.core.mail.backends.smtp.EmailBackend&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;OPTIONS&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;host&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;smtp.example.net&quot;</span><span class=\"p\">,</span>\n            <span class=\"s2\">&quot;use_tls&quot;</span><span class=\"p\">:</span> <span class=\"kc\">True</span><span class=\"p\">,</span>\n            <span class=\"s2\">&quot;username&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;my-app&quot;</span><span class=\"p\">,</span>\n            <span class=\"s2\">&quot;password&quot;</span><span class=\"p\">:</span> os<span class=\"o\">.</span>environ<span class=\"p\">[</span><span class=\"s2\">&quot;MY_APP_SMTP_PASSWORD&quot;</span><span class=\"p\">],</span>\n            <span class=\"s2\">&quot;timeout&quot;</span><span class=\"p\">:</span> <span class=\"mi\">10</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<aside class=\"version-note version-deprecated\" data-version=\"6.1\" role=\"note\">\n<p class=\"version-note-title\">Deprecated since Django 6.1</p><p><span class=\"versionmodified deprecated\">バージョン 6.1 で非推奨: </span>When the <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> setting is not defined, Django uses the SMTP\nbackend as the default mailer (the default <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-EMAIL_BACKEND\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_BACKEND</code></a>),\nconnecting to localhost on port 25. This behavior will be removed in Django\n7.0, which will not have a default mailer configuration.</p>\n<p>When the SMTP backend is used without <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> defined,\nthe options listed above are obtained from the deprecated\n<a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-EMAIL_HOST\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_HOST</code></a>, <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-EMAIL_PORT\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_PORT</code></a>, <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-EMAIL_HOST_USER\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_HOST_USER</code></a>,\n<a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-EMAIL_HOST_PASSWORD\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_HOST_PASSWORD</code></a>, <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-EMAIL_USE_TLS\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_USE_TLS</code></a>,\n<a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-EMAIL_USE_SSL\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_USE_SSL</code></a>, <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-EMAIL_SSL_KEYFILE\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_SSL_KEYFILE</code></a>,\n<a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-EMAIL_SSL_CERTFILE\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_SSL_CERTFILE</code></a>, and <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-EMAIL_TIMEOUT\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_TIMEOUT</code></a> settings,\nrespectively. (There is no setting equivalent to the <code class=\"docutils literal notranslate\">&quot;fail_silently&quot;</code>\noption.)</p>\n</aside>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.core.mail.backends.smtp.EmailBackend\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-prename descclassname\">backends.smtp.</span><span class=\"sig-name descname\">EmailBackend</span><a class=\"heading-anchor\" href=\"#django.core.mail.backends.smtp.EmailBackend\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Directly instantiating an <code class=\"docutils literal notranslate\">EmailBackend</code> class is not recommended. Use\n<a class=\"reference internal\" href=\"#django.core.mail.mailers\" title=\"django.core.mail.mailers\"><code class=\"xref py py-data docutils literal notranslate\">mailers</code></a> to obtain a backend instance.</p>\n<p>When constructed directly (without going through <a class=\"reference internal\" href=\"#django.core.mail.mailers\" title=\"django.core.mail.mailers\"><code class=\"xref py py-data docutils literal notranslate\">mailers</code></a>), the SMTP\n<code class=\"docutils literal notranslate\">EmailBackend</code> class accepts the options listed above as keyword\narguments. Default values come from the corresponding, deprecated\n<code class=\"docutils literal notranslate\">EMAIL_*</code> settings. <code class=\"docutils literal notranslate\">host</code> is not required and defaults to\n<code class=\"docutils literal notranslate\">&quot;localhost&quot;</code>, and <code class=\"docutils literal notranslate\">port</code> defaults to <code class=\"docutils literal notranslate\">25</code> even if <code class=\"docutils literal notranslate\">use_tls</code> or\n<code class=\"docutils literal notranslate\">use_ssl</code> is True.</p>\n<p>When the <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> setting is defined, attempting to directly\ncreate an SMTP <code class=\"docutils literal notranslate\">EmailBackend</code> will raise an <code class=\"docutils literal notranslate\">AttributeError</code>.</p>\n<aside class=\"version-note version-deprecated\" data-version=\"6.1\" role=\"note\">\n<p class=\"version-note-title\">Deprecated since Django 6.1</p><p><span class=\"versionmodified deprecated\">バージョン 6.1 で非推奨: </span>Directly constructing an instance of an <code class=\"docutils literal notranslate\">EmailBackend</code> class will be\nunsupported in Django 2028. Undocumented use will result in different\ndefault argument handling compared to earlier releases.</p>\n</aside>\n</dd></dl>\n\n<section id=\"private-and-self-signed-smtp-server-certificates\">\n<span id=\"topic-email-smtp-private-ca\"></span><h4>Private and self-signed SMTP server certificates<a class=\"heading-anchor\" href=\"#private-and-self-signed-smtp-server-certificates\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>If the SMTP server uses an SSL certificate from a private certificate authority\n(CA), the CA's root certificate should be added to the system CA bundle on the\nclient (where Django is running). Likewise, if the server uses a self-signed\ncertificate, it should be added to the client's system CA bundle so it can be\ntrusted. (The SMTP backend's <code class=\"docutils literal notranslate\">&quot;ssl_certfile&quot;</code> option cannot be used for CA\nroots or self-signed certificates.)</p>\n<p>Follow platform-specific instructions for adding to the system CA bundle. If\nmodifying the system bundle is not possible or desired, an alternative is using\nOpenSSL's <code class=\"docutils literal notranslate\">SSL_CERT_FILE</code> or <code class=\"docutils literal notranslate\">SSL_CERT_DIR</code> environment variables to\nspecify a custom certificate bundle.</p>\n<p>For more complex scenarios, the SMTP backend can be subclassed to add root\ncertificates to its <code class=\"docutils literal notranslate\">ssl_context</code> using\n<a class=\"reference external\" href=\"https://docs.python.org/3/library/ssl.html#ssl.SSLContext.load_verify_locations\" title=\"(in Python v3.14)\"><code class=\"xref py py-meth docutils literal notranslate\">ssl.SSLContext.load_verify_locations()</code></a>.</p>\n</section>\n</section>\n<section id=\"console-backend\">\n<span id=\"topic-email-console-backend\"></span><h3>コンソールバックエンド<a class=\"heading-anchor\" href=\"#console-backend\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Instead of sending out real emails, the console backend writes the emails that\nwould be sent to the standard output. To use it, set <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS-BACKEND\"><code class=\"xref std std-setting docutils literal notranslate\">BACKEND</code></a> to <code class=\"docutils literal notranslate\">&quot;django.core.mail.backends.console.EmailBackend&quot;</code>.</p>\n<p>The console backend supports these <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\">OPTIONS</code></a>:</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\">&quot;stream&quot;</code>: a stream-like object to write to. Defaults to <code class=\"docutils literal notranslate\">stdout</code>.</p></li>\n<li><p><code class=\"docutils literal notranslate\">&quot;fail_silently&quot;</code>: set to <code class=\"docutils literal notranslate\">True</code> to ignore <em>all</em> errors while writing the\nmessage to the stream, including errors serializing the message. (This option\nis available for backward compatibility but is not recommended.)</p></li>\n</ul>\n<p>このバックエンドはプロダクトでの使用を想定していません -- 開発中の利便性のために提供されています。</p>\n<aside class=\"version-note version-changed\" data-version=\"6.1\" role=\"note\">\n<p class=\"version-note-title\">Changed in Django 6.1</p><p>The settings file created by <a class=\"reference internal\" href=\"/ja/6.1/ref/django-admin/#django-admin-startproject\"><code class=\"xref std std-djadmin docutils literal notranslate\">startproject</code></a> now defines\n<a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> with the console backend as the default configuration.</p>\n</aside>\n</section>\n<section id=\"file-backend\">\n<span id=\"topic-email-file-backend\"></span><h3>ファイルバックエンド<a class=\"heading-anchor\" href=\"#file-backend\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>The file backend writes emails to a file. A new file is created for each new\nsession that is opened on this backend. To use it, set <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS-BACKEND\"><code class=\"xref std std-setting docutils literal notranslate\">BACKEND</code></a> to <code class=\"docutils literal notranslate\">&quot;django.core.mail.backends.filebased.EmailBackend&quot;</code>.</p>\n<p>The file backend supports these <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\">OPTIONS</code></a>:</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\">&quot;file_path&quot;</code> (required): the directory to which the files are written. Can\nbe a string or a <a class=\"reference external\" href=\"https://docs.python.org/3/library/pathlib.html#pathlib.Path\" title=\"(in Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">pathlib.Path</code></a> object. If the directory does not\nexist, the file backend will attempt to create it.</p></li>\n<li><p><code class=\"docutils literal notranslate\">&quot;fail_silently&quot;</code>: set to <code class=\"docutils literal notranslate\">True</code> to ignore <em>all</em> errors while writing the\nmessage to the file -- including errors serializing the message -- but <em>not</em>\nerrors related to ensuring the file path directory exists. (This option is\navailable for backward compatibility but is not recommended.)</p></li>\n</ul>\n<p>このバックエンドはプロダクトでの使用を想定していません -- 開発中の利便性のために提供されています。</p>\n<aside class=\"version-note version-deprecated\" data-version=\"6.1\" role=\"note\">\n<p class=\"version-note-title\">Deprecated since Django 6.1</p><p><span class=\"versionmodified deprecated\">バージョン 6.1 で非推奨: </span>When the file backend is used without the <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> setting\ndefined, it will get its <code class=\"docutils literal notranslate\">file_path</code> option from the\n<a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-EMAIL_FILE_PATH\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_FILE_PATH</code></a> setting.</p>\n</aside>\n</section>\n<section id=\"in-memory-backend\">\n<span id=\"topic-email-memory-backend\"></span><h3>インメモリーバックエンド<a class=\"heading-anchor\" href=\"#in-memory-backend\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>The <code class=\"docutils literal notranslate\">'locmem'</code> backend stores messages in a special attribute of the\n<code class=\"docutils literal notranslate\">django.core.mail</code> module. The <code class=\"docutils literal notranslate\">outbox</code> attribute is created when the first\nmessage is sent. It's a list with an <a class=\"reference internal\" href=\"#django.core.mail.EmailMessage\" title=\"django.core.mail.EmailMessage\"><code class=\"xref py py-class docutils literal notranslate\">EmailMessage</code></a> instance for each\nmessage that would be sent. Messages in the outbox are annotated with a\n<code class=\"docutils literal notranslate\">sent_using</code> attribute that identifies the <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> alias used to\nsend the message.</p>\n<p>To use the in-memory backend, set <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS-BACKEND\"><code class=\"xref std std-setting docutils literal notranslate\">BACKEND</code></a> to\n<code class=\"docutils literal notranslate\">&quot;django.core.mail.backends.locmem.EmailBackend&quot;</code>. It does not support any\n<a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\">OPTIONS</code></a>.</p>\n<p>Django's test runner <a class=\"reference internal\" href=\"/ja/6.1/topics/testing/tools/#topics-testing-email\"><span class=\"std std-ref\">automatically switches to this backend for testing</span></a>.</p>\n<p>このバックエンドはプロダクトでの使用を想定していません -- 開発とテストにおける利便性のために提供されています。</p>\n<aside class=\"version-note version-changed\" data-version=\"6.1\" role=\"note\">\n<p class=\"version-note-title\">Changed in Django 6.1</p><p>The <code class=\"docutils literal notranslate\">sent_using</code> attribute was added to messages in the outbox.</p>\n</aside>\n</section>\n<section id=\"dummy-backend\">\n<span id=\"topic-email-dummy-backend\"></span><h3>ダミーバックエンド<a class=\"heading-anchor\" href=\"#dummy-backend\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>As the name suggests the dummy backend does nothing with your messages. To use\nit, set <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS-BACKEND\"><code class=\"xref std std-setting docutils literal notranslate\">BACKEND</code></a> to\n<code class=\"docutils literal notranslate\">&quot;django.core.mail.backends.dummy.EmailBackend&quot;</code>. It does not support any\n<a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\">OPTIONS</code></a>.</p>\n<p>このバックエンドはプロダクトでの使用を想定していません -- 開発中の利便性のために提供されています。</p>\n</section>\n<section id=\"third-party-backends\">\n<span id=\"topic-third-party-email-backends\"></span><h3>Third-party backends<a class=\"heading-anchor\" href=\"#third-party-backends\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<aside class=\"admonition-there-are-community-maintained-solutions admonition\" role=\"note\">\n<p class=\"admonition-title\">There are community-maintained solutions!</p>\n<p>Django has a vibrant ecosystem. There are email backends\nhighlighted on the <a class=\"reference external\" href=\"https://www.djangoproject.com/community/ecosystem/#email-notifications\">Community Ecosystem</a> page. The Django Packages\n<a class=\"reference external\" href=\"https://djangopackages.org/grids/g/email/\">Email grid</a> has even more options for you!</p>\n</aside>\n<p>Third-party email backends are available that:</p>\n<ul class=\"simple\">\n<li><p>Integrate directly with commercial email service providers' APIs (which often\nhave extra functionality not available through SMTP).</p></li>\n<li><p>Offload email sending to asynchronous task queues.</p></li>\n<li><p>Add features to other email backends, such as enforcing do-not-send lists or\nlogging sent messages.</p></li>\n<li><p>Provide development and debugging tools, such as sandbox capture and\nin-browser email previews.</p></li>\n</ul>\n</section>\n<section id=\"defining-a-custom-email-backend\">\n<span id=\"topic-custom-email-backend\"></span><h3>独自のメールバックエンドを定義する<a class=\"heading-anchor\" href=\"#defining-a-custom-email-backend\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>If you need to change how emails are sent you can write your own email backend.\nTo use a custom backend, set <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS-BACKEND\"><code class=\"xref std std-setting docutils literal notranslate\">BACKEND</code></a> to the Python\nimport path for your backend class and <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\">OPTIONS</code></a> to\nany <code class=\"docutils literal notranslate\">__init__()</code> keyword arguments your backend supports.</p>\n<p>Custom email backends should subclass <code class=\"docutils literal notranslate\">BaseEmailBackend</code> that is located in\nthe <code class=\"docutils literal notranslate\">django.core.mail.backends.base</code> module. A custom email backend must\nimplement the <code class=\"docutils literal notranslate\">send_messages(email_messages)</code> method. This method receives a\nlist of <a class=\"reference internal\" href=\"#django.core.mail.EmailMessage\" title=\"django.core.mail.EmailMessage\"><code class=\"xref py py-class docutils literal notranslate\">EmailMessage</code></a> instances and returns the number of successfully\ndelivered messages. If your backend has any concept of a persistent session or\nconnection, you should also implement the <code class=\"docutils literal notranslate\">open()</code> and <code class=\"docutils literal notranslate\">close()</code> methods.\nRefer to <code class=\"docutils literal notranslate\">smtp.EmailBackend</code> for a reference implementation.</p>\n</section>\n<section id=\"obtaining-an-instance-of-an-email-backend\">\n<span id=\"topic-mailers\"></span><h3>メールバックエンドのインスタンスを取得する<a class=\"heading-anchor\" href=\"#obtaining-an-instance-of-an-email-backend\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>The <code class=\"docutils literal notranslate\">mailers</code> factory in <code class=\"xref py py-mod docutils literal notranslate\">django.core.mail</code> returns instances of email\nbackends.</p>\n<dl class=\"py data\">\n<dt class=\"sig sig-object py\" id=\"django.core.mail.mailers\">\n<span class=\"sig-name descname\">mailers</span><a class=\"heading-anchor\" href=\"#django.core.mail.mailers\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><aside class=\"version-note version-added\" data-version=\"6.1\" role=\"note\">\n<p class=\"version-note-title\">New in Django 6.1</p></aside>\n<p>You can access the mailers configured in the <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> setting\nthrough a dict-like object: <code class=\"docutils literal notranslate\">django.core.mail.mailers</code>:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.core.mail</span> <span class=\"kn\">import</span> mailers\n<span class=\"gp\">&gt;&gt;&gt; </span>mailers<span class=\"p\">[</span><span class=\"s2\">&quot;notifications&quot;</span><span class=\"p\">]</span>\n</code></pre></div>\n<p>If the named key is not defined, a <code class=\"docutils literal notranslate\">MailerDoesNotExist</code> error will be\nraised. Other configuration problems will raise an <code class=\"docutils literal notranslate\">InvalidMailer</code> error.</p>\n</dd></dl>\n\n<dl class=\"py data\">\n<dt class=\"sig sig-object py\" id=\"django.core.mail.mailers.default\">\n<span class=\"sig-prename descclassname\">mailers.</span><span class=\"sig-name descname\">default</span><a class=\"heading-anchor\" href=\"#django.core.mail.mailers.default\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><aside class=\"version-note version-added\" data-version=\"6.1\" role=\"note\">\n<p class=\"version-note-title\">New in Django 6.1</p></aside>\n<p>As a shortcut, the default mailer can be accessed through\n<code class=\"docutils literal notranslate\">django.core.mail.mailers.default</code>:</p>\n<div class=\"code-block\" data-language=\"pycon\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Python console</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Python console code\"><code><span class=\"gp\">&gt;&gt;&gt; </span><span class=\"kn\">from</span> <span class=\"nn\">django.core.mail</span> <span class=\"kn\">import</span> mailers\n<span class=\"gp\">&gt;&gt;&gt; </span>mailers<span class=\"o\">.</span>default\n</code></pre></div>\n<p>This is equivalent to <code class=\"docutils literal notranslate\">mailers[&quot;default&quot;]</code>. If no default mailer has\nbeen configured, a <code class=\"docutils literal notranslate\">MailerDoesNotExist</code> error will be raised.</p>\n<aside class=\"version-note version-deprecated\" data-version=\"6.1\" role=\"note\">\n<p class=\"version-note-title\">Deprecated since Django 6.1</p><p><span class=\"versionmodified deprecated\">バージョン 6.1 で非推奨: </span>If the <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> setting is not defined, <code class=\"docutils literal notranslate\">mailers.default</code>\nwill create an email backend instance from the deprecated\n<a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-EMAIL_BACKEND\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_BACKEND</code></a> and related settings. This supports backward\ncompatibility with Django 6.0 and earlier.</p>\n<p>This behavior (and those settings) will be removed in Django 2028.</p>\n</aside>\n</dd></dl>\n\n<dl class=\"py function\">\n<dt class=\"sig sig-object py\" id=\"django.core.mail.get_connection\">\n<span class=\"sig-name descname\">get_connection</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">backend<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\"><span class=\"keyword-only-separator o\"><abbr title=\"Keyword-only parameters separator (PEP 3102)\">*</abbr></span></em>, <em class=\"sig-param\">fail_silently<span class=\"o\">=</span><span class=\"default_value\">False</span></em>, <em class=\"sig-param\"><span class=\"o\">**</span>kwargs</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.core.mail.get_connection\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>The deprecated <code class=\"xref py py-func docutils literal notranslate\">django.core.mail.get_connection()</code> function creates\nand returns an instance of an email backend. Its behavior depends on the\n<a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> setting and how the function is called.</p>\n<p>If the <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> setting <em>is</em> defined:</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\">get_connection()</code> with no arguments will return\n<a class=\"reference internal\" href=\"#django.core.mail.mailers.default\" title=\"django.core.mail.mailers.default\"><code class=\"xref py py-data docutils literal notranslate\">mailers.default</code></a>.</p></li>\n<li><p><code class=\"docutils literal notranslate\">get_connection(...)</code> called with only <code class=\"docutils literal notranslate\">fail_silently</code> or other\nkeyword arguments will create an instance of\n<code class=\"docutils literal notranslate\">MAILERS[&quot;default&quot;]</code> with any keywords added to the\ndefault mailer's <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\">OPTIONS</code></a>.</p></li>\n<li><p><code class=\"docutils literal notranslate\">get_connection(backend, ...)</code> with a backend import path will raise\nan error.</p></li>\n</ul>\n<p>If the <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> setting is <em>not</em> defined:</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\">get_connection()</code> with no arguments will return an instance of the\nemail backend specified in <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-EMAIL_BACKEND\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_BACKEND</code></a>.</p></li>\n<li><p>If you specify the <code class=\"docutils literal notranslate\">backend</code> argument, an instance of that backend will\nbe instantiated.</p></li>\n<li><p>If the keyword argument <code class=\"docutils literal notranslate\">fail_silently</code> is True, certain\nbackend-dependent exceptions during the email sending process will be\nsilently ignored.</p></li>\n<li><p>その他のキーワード引数はメールバックエンドのコンストラクタに直接渡されます。</p></li>\n</ul>\n<aside class=\"version-note version-deprecated\" data-version=\"6.0\" role=\"note\">\n<p class=\"version-note-title\">Deprecated since Django 6.0</p><p><span class=\"versionmodified deprecated\">バージョン 6.0 で非推奨: </span>Passing <code class=\"docutils literal notranslate\">fail_silently</code> as a positional argument is deprecated.</p>\n</aside>\n<aside class=\"version-note version-deprecated\" data-version=\"6.1\" role=\"note\">\n<p class=\"version-note-title\">Deprecated since Django 6.1</p><p><span class=\"versionmodified deprecated\">バージョン 6.1 で非推奨: </span><code class=\"xref py py-func docutils literal notranslate\">get_connection()</code> is deprecated and will be removed in Django\n7.0. Switch to <a class=\"reference internal\" href=\"#django.core.mail.mailers\" title=\"django.core.mail.mailers\"><code class=\"xref py py-data docutils literal notranslate\">mailers[alias]</code></a>. See\n<a class=\"reference internal\" href=\"/ja/6.1/howto/mailers-migration/#migrating-to-mailers-get-connection\"><span class=\"std std-ref\">Replacing get_connection() and connection arguments</span></a> for migration suggestions.</p>\n</aside>\n</dd></dl>\n\n</section>\n<section id=\"email-backend-api\">\n<span id=\"topic-email-backend-api\"></span><h3>Email backend API<a class=\"heading-anchor\" href=\"#email-backend-api\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Instances of an email backend class have the following methods:</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\">open()</code> は、長寿命のメール送信のコネクションをインスタンス化します。</p></li>\n<li><p><code class=\"docutils literal notranslate\">close()</code> は、現在のメール送信のコネクションを閉じます。</p></li>\n<li><p><code class=\"docutils literal notranslate\">send_messages(email_messages)</code> sends a list of <a class=\"reference internal\" href=\"#django.core.mail.EmailMessage\" title=\"django.core.mail.EmailMessage\"><code class=\"xref py py-class docutils literal notranslate\">EmailMessage</code></a>\nobjects. If the connection is not open, this call will implicitly open the\nconnection, and close the connection afterward. If the connection is already\nopen, it will be left open after mail has been sent.</p></li>\n</ul>\n<p>A backend instance can also be used as a context manager, which will\nautomatically call <code class=\"docutils literal notranslate\">open()</code> and <code class=\"docutils literal notranslate\">close()</code> as needed. An example is in\n<a class=\"reference internal\" href=\"#topics-sending-multiple-emails\"><span class=\"std std-ref\">Sending many messages efficiently</span></a>.</p>\n</section>\n</section>\n<section id=\"configuring-email-for-development\">\n<h2>開発用にメールを設定する<a class=\"heading-anchor\" href=\"#configuring-email-for-development\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Django に電子メールをまったく送信させたくない場合もあるでしょう。たとえば、ウェブサイトの開発中に数千通のメールを送信したくはないでしょう。しかし、適切な条件で適切な人々にメールが送信され、これらのメールが正しい内容を含んでいるか検証したいことがあるかもしれません。</p>\n<p>ローカル開発用にメールを設定する最も簡単な方法は <a class=\"reference internal\" href=\"#topic-email-console-backend\"><span class=\"std std-ref\">console</span></a> メールバックエンドを使うことです。このバックエンドはすべてのメールを <code class=\"docutils literal notranslate\">stdout</code> にリダイレクトし、メールの内容を検査できるようにします。</p>\n<p><a class=\"reference internal\" href=\"#topic-email-file-backend\"><span class=\"std std-ref\">ファイル</span></a> メールバックエンドも開発に役立ちます。このバックエンドは全ての SMTP コネクションをファイルにダンプし、都合の良いときに調べられるようにします。</p>\n<p>Another approach is to use a mocked SMTP server that receives the emails\nlocally and displays them to the terminal, but does not actually send\nanything. The <a class=\"extlink-pypi reference external\" href=\"https://pypi.org/project/aiosmtpd/\">aiosmtpd</a> package provides a way to accomplish this:</p>\n<div class=\"code-block\" data-language=\"shell\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Shell</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Shell code\"><code>python -m pip install <span class=\"s2\">&quot;aiosmtpd &gt;= 1.4.5&quot;</span>\n\npython -m aiosmtpd -n -l localhost:8025\n</code></pre></div>\n<p>This command will start a minimal SMTP server listening on port 8025 of\nlocalhost. This server prints to standard output all email headers and the\nemail body. You then only need to set an SMTP backend's <code class=\"docutils literal notranslate\">&quot;host&quot;</code> and\n<code class=\"docutils literal notranslate\">&quot;port&quot;</code> <a class=\"reference internal\" href=\"/ja/6.1/ref/settings/#std-setting-MAILERS-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\">OPTIONS</code></a> accordingly. For a more\ndetailed discussion of SMTP server options, see the documentation of the\n<a class=\"reference external\" href=\"https://aiosmtpd.readthedocs.io/en/latest/\">aiosmtpd</a> module.</p>\n<p>アプリケーションでのメール送信のユニットテストについては、テストのドキュメントの <a class=\"reference internal\" href=\"/ja/6.1/topics/testing/tools/#topics-testing-email\"><span class=\"std std-ref\">メールサービス</span></a> セクションを参照してください。</p>\n</section>","rootId":"module-django.core.mail","toc":[{"title":"簡単な例","anchor":"quick-examples","children":[]},{"title":"Configuring email","anchor":"configuring-email","children":[{"title":"Multiple mailers","anchor":"multiple-mailers","children":[]}]},{"title":"Sending messages","anchor":"sending-messages","children":[{"title":"send_mail()","anchor":"send-mail","children":[]},{"title":"send_mass_mail()","anchor":"send-mass-mail","children":[{"title":"send_mass_mail() と send_mail() の比較","anchor":"send-mass-mail-vs-send-mail","children":[]}]},{"title":"mail_admins()","anchor":"mail-admins","children":[]},{"title":"mail_managers()","anchor":"mail-managers","children":[]},{"title":"EmailMessage クラス","anchor":"the-emailmessage-class","children":[{"title":"代替のコンテンツタイプを送信する","anchor":"sending-alternative-content-types","children":[{"title":"複数のバージョンを持つコンテンツを送る","anchor":"sending-multiple-content-versions","children":[]},{"title":"デフォルトのコンテンツタイプを変更する","anchor":"updating-the-default-content-type","children":[]}]}]},{"title":"Safely sending email","anchor":"safely-sending-email","children":[{"title":"Formatting email addresses","anchor":"formatting-email-addresses","children":[]},{"title":"ヘッダインジェクションを防止する","anchor":"preventing-header-injection","children":[]}]},{"title":"Sending many messages efficiently","anchor":"sending-many-messages-efficiently","children":[]}]},{"title":"メールのバックエンド","anchor":"email-backends","children":[{"title":"SMTP バックエンド","anchor":"smtp-backend","children":[{"title":"Private and self-signed SMTP server certificates","anchor":"private-and-self-signed-smtp-server-certificates","children":[]}]},{"title":"コンソールバックエンド","anchor":"console-backend","children":[]},{"title":"ファイルバックエンド","anchor":"file-backend","children":[]},{"title":"インメモリーバックエンド","anchor":"in-memory-backend","children":[]},{"title":"ダミーバックエンド","anchor":"dummy-backend","children":[]},{"title":"Third-party backends","anchor":"third-party-backends","children":[]},{"title":"独自のメールバックエンドを定義する","anchor":"defining-a-custom-email-backend","children":[]},{"title":"メールバックエンドのインスタンスを取得する","anchor":"obtaining-an-instance-of-an-email-backend","children":[]},{"title":"Email backend API","anchor":"email-backend-api","children":[]}]},{"title":"開発用にメールを設定する","anchor":"configuring-email-for-development","children":[]}],"breadcrumbs":[{"docname":"topics/index","title":"Django を使う","url":"/ja/6.1/topics/"}],"prev":{"docname":"topics/signing","title":"暗号署名","url":"/ja/6.1/topics/signing/"},"next":{"docname":"topics/i18n/index","title":"国際化とローカライズ","url":"/ja/6.1/topics/i18n/"},"formats":{"html":"/ja/6.1/topics/email/","markdown":"/ja/6.1/topics/email.md","json":"/ja/6.1/topics/email.json"},"source":"https://github.com/django/django/blob/stable/6.1.x/docs/topics/email.txt","official":"https://docs.djangoproject.com/ja/6.1/topics/email/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0","1.11","1.10","1.9"],"inLocales":["en","sv","zh-hans","ga","fr","ja","id","it","pt-br","ko","es","el","pl"]}