{"title":"Mengirim surel","version":"6.0","locale":"id","docname":"topics/email","url":"/id/6.0/topics/email/","canonical":"https://djangodocs.dev/id/6.0/topics/email/","summary":"Although Python provides a mail sending interface via the smtplib module, Django provides a couple of light wrappers over it.","html":"<span id=\"sending-email\"></span><h1>Mengirim surel<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>Although Python provides a mail sending interface via the <a class=\"reference external\" href=\"https://docs.python.org/3/library/smtplib.html#module-smtplib\" title=\"(di Python v3.14)\"><code class=\"xref py py-mod docutils literal notranslate\">smtplib</code></a>\nmodule, Django provides a couple of light wrappers over it. These wrappers are\nprovided to make sending email extra quick, to help test email sending during\ndevelopment, and to provide support for platforms that can't use SMTP.</p>\n<p>Kode tinggal dalam modul <code class=\"docutils literal notranslate\">django.core.mail</code>.</p>\n<section id=\"quick-examples\">\n<h2>Quick examples<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>Use <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> for straightforward email sending. For example, to send a\nplain text message:</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    fail_silently<span class=\"o\">=</span><span class=\"kc\">False</span><span class=\"p\">,</span>\n<span class=\"p\">)</span>\n</code></pre></div>\n<p>When additional email sending functionality is needed, use\n<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 <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>. For example, to send\na multipart email that includes both HTML and plain text versions with a\nspecific template and custom headers, you can use the following 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<p>Surat dikirim menggunakan rumah SMTP dan port ditentukan dalam pengaturan <a class=\"reference internal\" href=\"/id/6.0/ref/settings/#std-setting-EMAIL_HOST\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_HOST</code></a> dan <a class=\"reference internal\" href=\"/id/6.0/ref/settings/#std-setting-EMAIL_PORT\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_PORT</code></a>. Pengaturan <a class=\"reference internal\" href=\"/id/6.0/ref/settings/#std-setting-EMAIL_HOST_USER\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_HOST_USER</code></a> dan <a class=\"reference internal\" href=\"/id/6.0/ref/settings/#std-setting-EMAIL_HOST_PASSWORD\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_HOST_PASSWORD</code></a> settings, jika disetel, digunakan untuk mengotentifikasi pada peladen SMTP, dan pengaturan  <a class=\"reference internal\" href=\"/id/6.0/ref/settings/#std-setting-EMAIL_USE_TLS\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_USE_TLS</code></a> dan <a class=\"reference internal\" href=\"/id/6.0/ref/settings/#std-setting-EMAIL_USE_SSL\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_USE_SSL</code></a> mengendalikan apakah hubungan aman digunakan.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Catatan</p>\n<p>Kumpulan karakter dari surel dikirim dengan <code class=\"docutils literal notranslate\">django.core.mail</code> akan disetel ke nilai dari pengaturan <a class=\"reference internal\" href=\"/id/6.0/ref/settings/#std-setting-DEFAULT_CHARSET\"><code class=\"xref std std-setting docutils literal notranslate\">DEFAULT_CHARSET</code></a> anda.</p>\n</aside>\n</section>\n<section id=\"send-mail\">\n<h2><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></h2>\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>Dalam kebanyakan kasus, anda dapat mengirim surel menggunakan <code class=\"docutils literal notranslate\">django.core.mail.send_mail()</code>.</p>\n<p>Parameter <code class=\"docutils literal notranslate\">subject</code>, <code class=\"docutils literal notranslate\">message</code>, <code class=\"docutils literal notranslate\">from_email</code> dan <code class=\"docutils literal notranslate\">recipient_list</code> dibutuhkan.</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\">subject</code>: Sebuah string.</p></li>\n<li><p><code class=\"docutils literal notranslate\">message</code>: Sebuah string.</p></li>\n<li><p><code class=\"docutils literal notranslate\">from_email</code>: Sebuah string. Jika <code class=\"docutils literal notranslate\">None</code>, Django aan menggunakan nilai dari pengaturan <a class=\"reference internal\" href=\"/id/6.0/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>: Sebuah daftar dari string, setiap alamat surel. Setiap anggota dari <code class=\"docutils literal notranslate\">recipient_list</code> akan melihat penerima lain dalam bidang &quot;To:&quot; dari pesan surel.</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. When it's <code class=\"docutils literal notranslate\">False</code>, <code class=\"docutils literal notranslate\">send_mail()</code> will raise\nan <a class=\"reference external\" href=\"https://docs.python.org/3/library/smtplib.html#smtplib.SMTPException\" title=\"(di Python v3.14)\"><code class=\"xref py py-exc docutils literal notranslate\">smtplib.SMTPException</code></a> if an error occurs. See the <a class=\"reference external\" href=\"https://docs.python.org/3/library/smtplib.html#module-smtplib\" title=\"(di Python v3.14)\"><code class=\"xref py py-mod docutils literal notranslate\">smtplib</code></a>\ndocs for a list of possible exceptions, all of which are subclasses of\n<a class=\"reference external\" href=\"https://docs.python.org/3/library/smtplib.html#smtplib.SMTPException\" title=\"(di Python v3.14)\"><code class=\"xref py py-exc docutils literal notranslate\">SMTPException</code></a>.</p></li>\n<li><p><code class=\"docutils literal notranslate\">auth_user</code>: Pilihan nama pengguna untuk digunakan mengautentifikasi ke peladen SMTP. Jika ini tidak disediakan, Django akan menggunakan nilai dari pengaturan <a class=\"reference internal\" href=\"/id/6.0/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>: Sandi pilihan digunakan untuk mengautentifikasi ke peladen SMTP. Jika ini tidak disediakan, Django akan menggunakan nilai dari pengaturan <a class=\"reference internal\" href=\"/id/6.0/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>: Backend surel pilihan digunakan untuk mengirim surat. Jika tidak ditentukan, sebuah instance dari backend awalan akan digunakan. Lihat dokumentasi pada <span class=\"xref std std-ref\">Email backends 1</span> untuk rincian lebih.</p></li>\n<li><p><code class=\"docutils literal notranslate\">html_message</code>: Jika <code class=\"docutils literal notranslate\">html_message</code> disediakan, surel dihasilkan akan berupa surel <em class=\"mimetype\">multipart/alternative</em> dengan <code class=\"docutils literal notranslate\">message</code> sebagai jenis isi  <em class=\"mimetype\">text/plain</em> dan <code class=\"docutils literal notranslate\">html_message</code> sebagai  jenis isi <em class=\"mimetype\">text/html</em>.</p></li>\n</ul>\n<p>Nilai kembalian akan berupa angka dari pesan terkirim yang berhasil (yang dapat berupa <code class=\"docutils literal notranslate\">0</code> atau <code class=\"docutils literal notranslate\">1</code> sejak itu hanya daoat mengirim satu pesan).</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\">Ditinggalkan sejak versi 6.0: </span>Passing <code class=\"docutils literal notranslate\">fail_silently</code> and later parameters as positional arguments is\ndeprecated.</p>\n</aside>\n</section>\n<section id=\"send-mass-mail\">\n<h2><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></h2>\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><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> diperuntukkan untuk menangani penyuratan elektronik masal.</p>\n<p><code class=\"docutils literal notranslate\">datatuple</code> adalah sebuah tuple yang setiap unsur adalah dalam bentuk ini:</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.</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>Sebagai contoh, kode berikut akan mengirim dua pesan berbeda pada dua kumpulan berbeda dari penerima; bagaimanapun, hanya satu hubungan ke peladen surat akan dibuka:</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> fail_silently<span class=\"o\">=</span><span class=\"kc\">False</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>Nilai kembalian akan berupa angka dari pesan terkirim berhasil.</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\">Ditinggalkan sejak versi 6.0: </span>Passing <code class=\"docutils literal notranslate\">fail_silently</code> and later parameters as positional arguments is\ndeprecated.</p>\n</aside>\n<section id=\"send-mass-mail-vs-send-mail\">\n<h3><code class=\"docutils literal notranslate\">send_mass_mail()</code> x <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></h3>\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 <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\nthat <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 server each time it's\nexecuted, 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 connection for all of its\nmessages. 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 more efficient.</p>\n</section>\n</section>\n<section id=\"mail-admins\">\n<h2><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></h2>\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><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> adalah jalan pintas untuk mengirim sebuah surel pada admin situs, seperti ditentukan dalam pengaturan <a class=\"reference internal\" href=\"/id/6.0/ref/settings/#std-setting-ADMINS\"><code class=\"xref std std-setting docutils literal notranslate\">ADMINS</code></a>.</p>\n<p><code class=\"docutils literal notranslate\">mail_admins()</code> mengawali subyek dengan nilai dari pengaturan <a class=\"reference internal\" href=\"/id/6.0/ref/settings/#std-setting-EMAIL_SUBJECT_PREFIX\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_SUBJECT_PREFIX</code></a>, yaitu <code class=\"docutils literal notranslate\">&quot;[Django] &quot;</code> secara awalan.</p>\n<p>Kepala &quot;From:&quot; dari surel akan berupa nilai dari pengaturan <a class=\"reference internal\" href=\"/id/6.0/ref/settings/#std-setting-SERVER_EMAIL\"><code class=\"xref std std-setting docutils literal notranslate\">SERVER_EMAIL</code></a>.</p>\n<p>Metode ini ada untuk kenyamanan dan kesiapan.</p>\n<p>Jika <code class=\"docutils literal notranslate\">html_message</code> disediakan, surel dihasilkan akan berupa surel <em class=\"mimetype\">multipart/alternative</em> dengan <code class=\"docutils literal notranslate\">message</code> seperti jenis isi <em class=\"mimetype\">text/plain</em> dan <code class=\"docutils literal notranslate\">html_message</code> seperti jenis isi <em class=\"mimetype\">text/html</em>.</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\">Ditinggalkan sejak versi 6.0: </span>Passing <code class=\"docutils literal notranslate\">fail_silently</code> and later parameters as positional arguments is\ndeprecated.</p>\n</aside>\n</section>\n<section id=\"mail-managers\">\n<h2><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></h2>\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><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> seperti <code class=\"docutils literal notranslate\">mail_admins()</code>, kecuali itu mengirim sebuah surel ke pengelola situs, seperti ditentukan dalam pengaturan <a class=\"reference internal\" href=\"/id/6.0/ref/settings/#std-setting-MANAGERS\"><code class=\"xref std std-setting docutils literal notranslate\">MANAGERS</code></a>.</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\">Ditinggalkan sejak versi 6.0: </span>Passing <code class=\"docutils literal notranslate\">fail_silently</code> and later parameters as positional arguments is\ndeprecated.</p>\n</aside>\n</section>\n<section id=\"examples\">\n<h2>Contoh<a class=\"heading-anchor\" href=\"#examples\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Ini mengirim surel tunggal kepada <a class=\"reference external\" href=\"mailto:john&#37;&#52;&#48;example&#46;com\">john<span>&#64;</span>example<span>&#46;</span>com</a> dan <a class=\"reference external\" href=\"mailto:jane&#37;&#52;&#48;example&#46;com\">jane<span>&#64;</span>example<span>&#46;</span>com</a>, dengan keduanya mereka muncul dalam &quot;To:&quot;:</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>This sends a message to <code class=\"docutils literal notranslate\">john&#64;example.com</code> and <code class=\"docutils literal notranslate\">jane&#64;example.com</code>, with\nthem both receiving a separate 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 id=\"preventing-header-injection\">\n<h2>Mencegah penyuntikan kepala<a class=\"heading-anchor\" href=\"#preventing-header-injection\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p><a class=\"reference external\" href=\"http://www.nyphp.org/phundamentals/8_Preventing-Email-Header-Injection.html\">Header injection</a> adalah memanfaatkan keamanan dimana seorang penyerang memasukkan kepala surel tambahan untuk mengendalikan &quot;To:&quot; dan &quot;From:&quot; dalam pesan-pesan surel yang tulisan-tulisan anda dibangkitkan.</p>\n<p>The Django email functions outlined above all protect against header injection\nby forbidding newlines in header values. If any <code class=\"docutils literal notranslate\">subject</code>, <code class=\"docutils literal notranslate\">from_email</code> or\n<code class=\"docutils literal notranslate\">recipient_list</code> contains a newline (in either Unix, Windows or Mac style),\nthe email function (e.g. <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>) will raise <a class=\"reference external\" href=\"https://docs.python.org/3/library/exceptions.html#ValueError\" title=\"(di Python v3.14)\"><code class=\"xref py py-exc docutils literal notranslate\">ValueError</code></a> and,\nhence, will not send the email. It's your responsibility to validate all data\nbefore passing it to the email functions.</p>\n<p>If a <code class=\"docutils literal notranslate\">message</code> contains headers at the start of the string, the headers will\nbe printed as the first bit of the email message.</p>\n<p>Here's an example view that takes a <code class=\"docutils literal notranslate\">subject</code>, <code class=\"docutils literal notranslate\">message</code> and <code class=\"docutils literal notranslate\">from_email</code>\nfrom the request's POST data, sends that to <code class=\"docutils literal notranslate\">admin&#64;example.com</code> and redirects\nto &quot;/contact/thanks/&quot; when it's done:</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\">django.http</span> <span class=\"kn\">import</span> HttpResponse<span class=\"p\">,</span> HttpResponseRedirect\n\n\n<span class=\"k\">def</span> <span class=\"nf\">send_email</span><span class=\"p\">(</span>request<span class=\"p\">):</span>\n    subject <span class=\"o\">=</span> request<span class=\"o\">.</span>POST<span class=\"o\">.</span>get<span class=\"p\">(</span><span class=\"s2\">&quot;subject&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;&quot;</span><span class=\"p\">)</span>\n    message <span class=\"o\">=</span> request<span class=\"o\">.</span>POST<span class=\"o\">.</span>get<span class=\"p\">(</span><span class=\"s2\">&quot;message&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;&quot;</span><span class=\"p\">)</span>\n    from_email <span class=\"o\">=</span> request<span class=\"o\">.</span>POST<span class=\"o\">.</span>get<span class=\"p\">(</span><span class=\"s2\">&quot;from_email&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;&quot;</span><span class=\"p\">)</span>\n    <span class=\"k\">if</span> subject <span class=\"ow\">and</span> message <span class=\"ow\">and</span> from_email<span class=\"p\">:</span>\n        <span class=\"k\">try</span><span class=\"p\">:</span>\n            send_mail<span class=\"p\">(</span>subject<span class=\"p\">,</span> message<span class=\"p\">,</span> from_email<span class=\"p\">,</span> <span class=\"p\">[</span><span class=\"s2\">&quot;admin@example.com&quot;</span><span class=\"p\">])</span>\n        <span class=\"k\">except</span> <span class=\"ne\">ValueError</span><span class=\"p\">:</span>\n            <span class=\"k\">return</span> HttpResponse<span class=\"p\">(</span><span class=\"s2\">&quot;Invalid header found.&quot;</span><span class=\"p\">)</span>\n        <span class=\"k\">return</span> HttpResponseRedirect<span class=\"p\">(</span><span class=\"s2\">&quot;/contact/thanks/&quot;</span><span class=\"p\">)</span>\n    <span class=\"k\">else</span><span class=\"p\">:</span>\n        <span class=\"c1\"># In reality we&#39;d use a form class</span>\n        <span class=\"c1\"># to get proper validation errors.</span>\n        <span class=\"k\">return</span> HttpResponse<span class=\"p\">(</span><span class=\"s2\">&quot;Make sure all fields are entered and valid.&quot;</span><span class=\"p\">)</span>\n</code></pre></div>\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</section>\n<section id=\"the-emailmessage-class\">\n<span id=\"emailmessage-and-smtpconnection\"></span><h2>Kelas <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></h2>\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\">Catatan</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<section id=\"emailmessage-objects\">\n<h3>Obyek <code class=\"docutils literal notranslate\">EmailMessage</code><a class=\"heading-anchor\" href=\"#emailmessage-objects\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\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>: Pokok baris dari surel.</p></li>\n<li><p><code class=\"docutils literal notranslate\">body</code>: Teks badan. Ini harus berupa pesan teks polos.</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 legal. If omitted, the\n<a class=\"reference internal\" href=\"/id/6.0/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>: Sebuah list atau tuple dari alamat-alamat penerima.</p></li>\n</ul>\n<p>The following parameters must be given as keyword arguments if used:</p>\n<ul>\n<li><p><code class=\"docutils literal notranslate\">cc</code>: Sebuah list atau tuple dari alamat-alamat penerima digunakan dalam kepala &quot;Cc&quot; ketika mengirim surel.</p></li>\n<li><p><code class=\"docutils literal notranslate\">bcc</code>: Sebuah list atau tuple dari alamat-alamat digunakan dalam kepala &quot;Bcc&quot; ketika mengirim surel.</p></li>\n<li><p><code class=\"docutils literal notranslate\">reply_to</code>: Sebuah list atau tuple dari alamat-alamat penerima dalam kepala &quot;Reply-To&quot; ketika mengirim surel.</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=\"(di 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=\"5.2\" role=\"note\">\n<p class=\"version-note-title\">Changed in Django 5.2</p><p>Support for <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> items of <code class=\"docutils literal notranslate\">attachments</code> was\nadded.</p>\n</aside>\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=\"(di 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\">Ditinggalkan sejak versi 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=\"(di 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=\"(di 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\">header</code>: Sebuah dictionary dari kepala tambahan untuk menaruh pesan. Kunci-kunci adalah nama kepala, nilai-nilai adalah nilai-nilai kepala. Itu terserah pada pemanggil untuk memastikan nama=nama dan nilai-nilai dalam bentuk benar untuk pesan surel. Atribut sesuai adalah <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.\nUse this parameter if you are sending the <code class=\"xref py py-class docutils literal notranslate\">EmailMessage</code> via\n<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> and you want to use the same connection for multiple\nmessages. If omitted, a new connection is created when <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> is\ncalled. This 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></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\">Ditinggalkan sejak versi 6.0: </span>Passing all except the first four parameters as positional arguments is\ndeprecated.</p>\n</aside>\n<p>Sebagai contoh:</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>Kelas mempunyai cara berikut:</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><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. If a connection was specified when the email was\nconstructed, that connection will be used. Otherwise, an instance of\nthe default backend will be instantiated and used. If the keyword\nargument <code class=\"docutils literal notranslate\">fail_silently</code> is <code class=\"docutils literal notranslate\">True</code>, exceptions raised while sending\nthe message will be quashed. An empty list of recipients will not raise\nan exception. It will return <code class=\"docutils literal notranslate\">1</code> if the message was sent\nsuccessfully, otherwise <code class=\"docutils literal notranslate\">0</code>.</p>\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=\"(di 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=\"(di 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=\"(di 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=\"(di 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=\"(di Python v3.14)\"><code class=\"xref py py-data docutils literal notranslate\">SMTPUTF8</code></a> or a custom\npolicy. For example,\n<a class=\"reference internal\" href=\"#django.core.mail.backends.smtp.EmailBackend\" title=\"django.core.mail.backends.smtp.EmailBackend\"><code class=\"xref py py-class docutils literal notranslate\">django.core.mail.backends.smtp.EmailBackend</code></a> uses the\n<a class=\"reference external\" href=\"https://docs.python.org/3/library/email.policy.html#email.policy.SMTP\" title=\"(di Python v3.14)\"><code class=\"xref py py-data docutils literal notranslate\">SMTP</code></a> policy to ensure <code class=\"docutils literal notranslate\">\\r\\n</code> line endings as\nrequired 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=\"(di 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>Sebagai contoh:</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=\"(di 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=\"(di Python v3.14)\"><code class=\"xref py py-class docutils literal notranslate\">email.message.Message</code></a>.</p>\n<p>For a <code class=\"docutils literal notranslate\">mimetype</code> starting with <em class=\"mimetype\">text/</em>, content is\nexpected to be a string. Binary data will be decoded using UTF-8,\nand if that fails, the MIME type will be changed to\n<em class=\"mimetype\">application/octet-stream</em> and the data will be attached\nunchanged.</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=\"(di 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=\"(di 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=\"(di 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\">Ditinggalkan sejak versi 6.0: </span>Support for <a class=\"reference external\" href=\"https://docs.python.org/3/library/email.mime.html#email.mime.base.MIMEBase\" title=\"(di 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=\"(di 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><aside class=\"version-note version-added\" data-version=\"5.2\" role=\"note\">\n<p class=\"version-note-title\">New in Django 5.2</p></aside>\n<p>A named tuple to store attachments to an email.</p>\n<p>The named tuple has the following indexes:</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>\n<section id=\"sending-alternative-content-types\">\n<h3>Mengirim pilihan lain jenis isi<a class=\"heading-anchor\" href=\"#sending-alternative-content-types\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<section id=\"sending-multiple-content-versions\">\n<h4>Sending multiple content versions<a class=\"heading-anchor\" href=\"#sending-multiple-content-versions\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\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 subclass 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> that allows additional versions of the\nmessage body in the email via the <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> method. This\ndirectly inherits all methods (including the class initialization) from\n<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>Alternatives should only be added using the <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>\nmethod, or passed to the constructor.</p>\n<aside class=\"version-note version-changed\" data-version=\"5.2\" role=\"note\">\n<p class=\"version-note-title\">Changed in Django 5.2</p><p>In older versions, <code class=\"docutils literal notranslate\">alternatives</code> was a list of regular tuples,\nas opposed to <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.</p>\n</aside>\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>Attach an alternative representation of the message body in the email.</p>\n<p>For example, to send a text and HTML combination, you could write:</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><aside class=\"version-note version-added\" data-version=\"5.2\" role=\"note\">\n<p class=\"version-note-title\">New in Django 5.2</p></aside>\n<p>Returns a boolean indicating whether the provided <code class=\"docutils literal notranslate\">text</code> is\ncontained in the email <code class=\"docutils literal notranslate\">body</code> and in all attached MIME type\n<code class=\"docutils literal notranslate\">text/*</code> alternatives.</p>\n<p>This can be useful when testing emails. 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=\"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><aside class=\"version-note version-added\" data-version=\"5.2\" role=\"note\">\n<p class=\"version-note-title\">New in Django 5.2</p></aside>\n<p>A named tuple to store alternative versions of email content.</p>\n<p>The named tuple has the following indexes:</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<h4>Updating the default content type<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></h4>\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=\"email-backends\">\n<span id=\"topic-email-backends\"></span><h2>Backend email<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>Pengiriman sebenarnya dari sebuah surel ditangani oleh backend email.</p>\n<p>Kelas backend surel mempunyai metode-metode berikut:</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\">open()</code> instantiates a long-lived email-sending connection.</p></li>\n<li><p><code class=\"docutils literal notranslate\">close()</code> menutup hubungan mengirim-surel saat ini.</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>Itu dapat juga digunakan sebagai pengelola konteks, yang akan otomatis memanggil <code class=\"docutils literal notranslate\">open()</code> dan <code class=\"docutils literal notranslate\">close()</code> sesuai kebutuhan:</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=\"k\">with</span> mail<span class=\"o\">.</span>get_connection<span class=\"p\">()</span> <span class=\"k\">as</span> connection<span class=\"p\">:</span>\n    mail<span class=\"o\">.</span>EmailMessage<span class=\"p\">(</span>\n        subject1<span class=\"p\">,</span>\n        body1<span class=\"p\">,</span>\n        from1<span class=\"p\">,</span>\n        <span class=\"p\">[</span>to1<span class=\"p\">],</span>\n        connection<span class=\"o\">=</span>connection<span class=\"p\">,</span>\n    <span class=\"p\">)</span><span class=\"o\">.</span>send<span class=\"p\">()</span>\n    mail<span class=\"o\">.</span>EmailMessage<span class=\"p\">(</span>\n        subject2<span class=\"p\">,</span>\n        body2<span class=\"p\">,</span>\n        from2<span class=\"p\">,</span>\n        <span class=\"p\">[</span>to2<span class=\"p\">],</span>\n        connection<span class=\"o\">=</span>connection<span class=\"p\">,</span>\n    <span class=\"p\">)</span><span class=\"o\">.</span>send<span class=\"p\">()</span>\n</code></pre></div>\n<section id=\"obtaining-an-instance-of-an-email-backend\">\n<h3>Mengambil sebuah instance dari sebuah backend surel.<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 <a class=\"reference internal\" href=\"#django.core.mail.get_connection\" title=\"django.core.mail.get_connection\"><code class=\"xref py py-func docutils literal notranslate\">get_connection()</code></a> function in <code class=\"docutils literal notranslate\">django.core.mail</code> returns an\ninstance of the email backend that you can use.</p>\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></dd></dl>\n\n<p>Secara awalan, sebuah panggilan pada <code class=\"docutils literal notranslate\">get_connection()</code> akan mengembalikan sebuah instance dari backend surel ditentukan dalam <a class=\"reference internal\" href=\"/id/6.0/ref/settings/#std-setting-EMAIL_BACKEND\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_BACKEND</code></a>. Jika anda menentukan argumen <code class=\"docutils literal notranslate\">backend</code>, sebuah instance dari backend itu akan diinstasiasikan.</p>\n<p>The keyword-only <code class=\"docutils literal notranslate\">fail_silently</code> argument controls how the backend should\nhandle errors. If <code class=\"docutils literal notranslate\">fail_silently</code> is True, exceptions during the email\nsending process will be silently ignored.</p>\n<p>All other keyword arguments are passed directly to the constructor of the\nemail backend.</p>\n<p>Django dikirim dengan beberapa backend pengiriman surel. Dengan pengecualian dari backend SMTP (yaitu awalan), backend ini hanya berguna selama percobaan dan pengembangan. Jika anda mempunyai persyaratan mengirim surel khusus, anda dapat <a class=\"reference internal\" href=\"#topic-custom-email-backend\"><span class=\"std std-ref\">write your own email backend</span></a>.</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\">Ditinggalkan sejak versi 6.0: </span>Passing <code class=\"docutils literal notranslate\">fail_silently</code> as positional argument is deprecated.</p>\n</aside>\n<section id=\"smtp-backend\">\n<span id=\"topic-email-smtp-backend\"></span><h4>Backend SMTP<a class=\"heading-anchor\" href=\"#smtp-backend\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\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><span class=\"sig-paren\">(</span><em class=\"sig-param\">host<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">port<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">username<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">password<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">use_tls<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">fail_silently<span class=\"o\">=</span><span class=\"default_value\">False</span></em>, <em class=\"sig-param\">use_ssl<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">timeout<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">ssl_keyfile<span class=\"o\">=</span><span class=\"default_value\">None</span></em>, <em class=\"sig-param\">ssl_certfile<span class=\"o\">=</span><span class=\"default_value\">None</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.backends.smtp.EmailBackend\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Ini adalah backend awalan. Surel akan dikirim melalui peladen SMTP.</p>\n<p>Nilai untuk setiap argumen diambil dari pencocokan pengaturan jika argumen adalah <code class=\"docutils literal notranslate\">None</code>:</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\">host</code>: <a class=\"reference internal\" href=\"/id/6.0/ref/settings/#std-setting-EMAIL_HOST\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_HOST</code></a></p></li>\n<li><p><code class=\"docutils literal notranslate\">port</code>: <a class=\"reference internal\" href=\"/id/6.0/ref/settings/#std-setting-EMAIL_PORT\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_PORT</code></a></p></li>\n<li><p><code class=\"docutils literal notranslate\">username</code>: <a class=\"reference internal\" href=\"/id/6.0/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\">password</code>: <a class=\"reference internal\" href=\"/id/6.0/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\">use_tls</code>: <a class=\"reference internal\" href=\"/id/6.0/ref/settings/#std-setting-EMAIL_USE_TLS\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_USE_TLS</code></a></p></li>\n<li><p><code class=\"docutils literal notranslate\">use_ssl</code>: <a class=\"reference internal\" href=\"/id/6.0/ref/settings/#std-setting-EMAIL_USE_SSL\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_USE_SSL</code></a></p></li>\n<li><p><code class=\"docutils literal notranslate\">timeout</code>: <a class=\"reference internal\" href=\"/id/6.0/ref/settings/#std-setting-EMAIL_TIMEOUT\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_TIMEOUT</code></a></p></li>\n<li><p><code class=\"docutils literal notranslate\">ssl_keyfile</code>: <a class=\"reference internal\" href=\"/id/6.0/ref/settings/#std-setting-EMAIL_SSL_KEYFILE\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_SSL_KEYFILE</code></a></p></li>\n<li><p><code class=\"docutils literal notranslate\">ssl_certfile</code>: <a class=\"reference internal\" href=\"/id/6.0/ref/settings/#std-setting-EMAIL_SSL_CERTFILE\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_SSL_CERTFILE</code></a></p></li>\n</ul>\n<p>Backend SMTP adalah konfigurasi awalan diwarisi oleh Django. Jika anda ingin menentukan itu secara jelas, taruh berikut dalam pengaturan anda:</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>EMAIL_BACKEND <span class=\"o\">=</span> <span class=\"s2\">&quot;django.core.mail.backends.smtp.EmailBackend&quot;</span>\n</code></pre></div>\n<p>If unspecified, the default <code class=\"docutils literal notranslate\">timeout</code> will be the one provided by\n<a class=\"reference external\" href=\"https://docs.python.org/3/library/socket.html#socket.getdefaulttimeout\" title=\"(di Python v3.14)\"><code class=\"xref py py-func docutils literal notranslate\">socket.getdefaulttimeout()</code></a>, which defaults to <code class=\"docutils literal notranslate\">None</code> (no timeout).</p>\n</dd></dl>\n\n</section>\n<section id=\"console-backend\">\n<span id=\"topic-email-console-backend\"></span><h4>Backend konsol<a class=\"heading-anchor\" href=\"#console-backend\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Daripada mengirim keluar surel asli backend konsol hanya menulis surel yang akan dikirim ke keluaran standar. Secara awalan, backend konsol menulis ke <code class=\"docutils literal notranslate\">stdout</code>. Anda dapat menggunakan obyek aliran-seperti berbeda dengan menyediakan argumen katakunci <code class=\"docutils literal notranslate\">stream</code> ketika membangun hubungan.</p>\n<p>Untuk menentukan backend ini, taruh berikut dalam pengaturan anda:</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>EMAIL_BACKEND <span class=\"o\">=</span> <span class=\"s2\">&quot;django.core.mail.backends.console.EmailBackend&quot;</span>\n</code></pre></div>\n<p>Backend ini tidak diperuntukkan untuk penggunaan dalam produksi -- itu disediakan sebagai kenyamanan yang dapat digunakan selama pengembangan.</p>\n</section>\n<section id=\"file-backend\">\n<span id=\"topic-email-file-backend\"></span><h4>Backend berkas<a class=\"heading-anchor\" href=\"#file-backend\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\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. The directory to which the files are\nwritten is either taken from the <a class=\"reference internal\" href=\"/id/6.0/ref/settings/#std-setting-EMAIL_FILE_PATH\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_FILE_PATH</code></a> setting or from the\n<code class=\"docutils literal notranslate\">file_path</code> keyword when creating a connection with <a class=\"reference internal\" href=\"#django.core.mail.get_connection\" title=\"django.core.mail.get_connection\"><code class=\"xref py py-func docutils literal notranslate\">get_connection()</code></a>.</p>\n<p>Untuk menentukan backend ini, taruh berikut dalam pengaturan anda:</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>EMAIL_BACKEND <span class=\"o\">=</span> <span class=\"s2\">&quot;django.core.mail.backends.filebased.EmailBackend&quot;</span>\nEMAIL_FILE_PATH <span class=\"o\">=</span> <span class=\"s2\">&quot;/tmp/app-messages&quot;</span>  <span class=\"c1\"># change this to a proper location</span>\n</code></pre></div>\n<p>Backend ini tidak diperuntukkan untuk penggunaan dalam produksi -- itu disediakan sebagai kenyamanan yang dapat digunakan selama pengembangan.</p>\n</section>\n<section id=\"in-memory-backend\">\n<span id=\"topic-email-memory-backend\"></span><h4>backend di-memory<a class=\"heading-anchor\" href=\"#in-memory-backend\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\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.</p>\n<p>Untuk menentukan backend ini, taruh berikut dalam pengaturan anda:</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>EMAIL_BACKEND <span class=\"o\">=</span> <span class=\"s2\">&quot;django.core.mail.backends.locmem.EmailBackend&quot;</span>\n</code></pre></div>\n<p>Backend ini tidak dimaksudkan untuk digunakan dalam produksi -- itu disediakan sebagai kenyamanan yang dapat digunakan selama pengembangan dan percobaan.</p>\n<p>Django's test runner <a class=\"reference internal\" href=\"/id/6.0/topics/testing/tools/#topics-testing-email\"><span class=\"std std-ref\">automatically uses this backend for testing</span></a>.</p>\n</section>\n<section id=\"dummy-backend\">\n<span id=\"topic-email-dummy-backend\"></span><h4>Backend tiruan<a class=\"heading-anchor\" href=\"#dummy-backend\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h4>\n<p>Ketika nama menganjurkan backend tiruan tidak melakukan apapun dengan pesan-pesan anda. Untuk menentukan backend ini, taruh berikut dalam pengaturan anda:</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>EMAIL_BACKEND <span class=\"o\">=</span> <span class=\"s2\">&quot;django.core.mail.backends.dummy.EmailBackend&quot;</span>\n</code></pre></div>\n<p>Backend ini tidak diperuntukkan untuk penggunaan dalam produksi -- itu disediakan sebagai kenyamanan yang dapat digunakan selama pengembangan.</p>\n<aside class=\"admonition-there-are-community-maintained-solutions-too admonition\" role=\"note\">\n<p class=\"admonition-title\">There are community-maintained solutions too!</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-and-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</section>\n</section>\n<section id=\"defining-a-custom-email-backend\">\n<span id=\"topic-custom-email-backend\"></span><h3>Menentukan penyesuaian backend surel<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>Jika anda butuh merubah bagaimana surel dikirim anda dapat menulis backend surel anda sendiri. Pengaturan <a class=\"reference internal\" href=\"/id/6.0/ref/settings/#std-setting-EMAIL_BACKEND\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_BACKEND</code></a> dalam berkas pengaturan anda adalah kemudian Pythn mengimpor jalur untuk kelas backend anda.</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=\"sending-multiple-emails\">\n<span id=\"topics-sending-multiple-emails\"></span><h3>Mengirim banyak surel<a class=\"heading-anchor\" href=\"#sending-multiple-emails\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>Membangun dan menutup hubungan SMTP (atau hubungan jaringan lain, untuk masalah itu) adalah sebuah pengolahan yang mahal. Jika anda mempunyai banyak surel untuk dikirim, itu masuk akal menggunakan kembali hubungan SMTP, daripada membuat dan manghancurkan hubungan setiap kali anda ingin mengirim surel.</p>\n<p>Ada dua cara memberitahu sebuah backend surel untuk menggunakan kembali sebuah hubungan.</p>\n<p>Firstly, you can use the <code class=\"docutils literal notranslate\">send_messages()</code> method on a connection. This takes\na 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 all\nusing that single connection. As a consequence, any <a class=\"reference internal\" href=\"#django.core.mail.EmailMessage\" title=\"django.core.mail.EmailMessage\"><code class=\"xref py py-class docutils literal notranslate\">connection</code></a> set on an individual message is ignored.</p>\n<p>For example, if you have a function called <code class=\"docutils literal notranslate\">get_notification_email()</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\nconnection <span class=\"o\">=</span> mail<span class=\"o\">.</span>get_connection<span class=\"p\">()</span>  <span class=\"c1\"># Use default email connection</span>\nmessages <span class=\"o\">=</span> get_notification_email<span class=\"p\">()</span>\nconnection<span class=\"o\">.</span>send_messages<span class=\"p\">(</span>messages<span class=\"p\">)</span>\n</code></pre></div>\n<p>Dalam contoh ini, panggilan pada <code class=\"docutils literal notranslate\">send_messages()</code> membuka hubungan pada backend, mengirim daftar pesan-pesan, dan kemudian menutup hubungan kembali.</p>\n<p>Pendekatan kedua adalah menggunakan metode <code class=\"docutils literal notranslate\">open()</code> dan <code class=\"docutils literal notranslate\">close()</code> pada backend surel untuk secara manual mengendalikan hubungan. <code class=\"docutils literal notranslate\">send_messages()</code> tidak akan secara manual membuka atau menutup hubungan jika itu sudah terbuka, jadi jika anda membuka secara munual hubungan, anda dapat mengendalikan ketika itu tertutup. Sebagai contoh:</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\nconnection <span class=\"o\">=</span> mail<span class=\"o\">.</span>get_connection<span class=\"p\">()</span>\n\n<span class=\"c1\"># Manually open the connection</span>\nconnection<span class=\"o\">.</span>open<span class=\"p\">()</span>\n\n<span class=\"c1\"># Construct an email message that uses the connection</span>\nemail1 <span class=\"o\">=</span> mail<span class=\"o\">.</span>EmailMessage<span class=\"p\">(</span>\n    <span class=\"s2\">&quot;Hello&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;Body goes here&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;to1@example.com&quot;</span><span class=\"p\">],</span>\n    connection<span class=\"o\">=</span>connection<span class=\"p\">,</span>\n<span class=\"p\">)</span>\nemail1<span class=\"o\">.</span>send<span class=\"p\">()</span>  <span class=\"c1\"># Send the email</span>\n\n<span class=\"c1\"># Construct two more messages</span>\nemail2 <span class=\"o\">=</span> mail<span class=\"o\">.</span>EmailMessage<span class=\"p\">(</span>\n    <span class=\"s2\">&quot;Hello&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;Body goes here&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;to2@example.com&quot;</span><span class=\"p\">],</span>\n<span class=\"p\">)</span>\nemail3 <span class=\"o\">=</span> mail<span class=\"o\">.</span>EmailMessage<span class=\"p\">(</span>\n    <span class=\"s2\">&quot;Hello&quot;</span><span class=\"p\">,</span>\n    <span class=\"s2\">&quot;Body goes here&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;to3@example.com&quot;</span><span class=\"p\">],</span>\n<span class=\"p\">)</span>\n\n<span class=\"c1\"># Send the two emails in a single call -</span>\nconnection<span class=\"o\">.</span>send_messages<span class=\"p\">([</span>email2<span class=\"p\">,</span> email3<span class=\"p\">])</span>\n<span class=\"c1\"># The connection was already open so send_messages() doesn&#39;t close it.</span>\n<span class=\"c1\"># We need to manually close the connection.</span>\nconnection<span class=\"o\">.</span>close<span class=\"p\">()</span>\n</code></pre></div>\n</section>\n</section>\n<section id=\"configuring-email-for-development\">\n<h2>Konfigurasi surel untuk pengembangan<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>Ada saatnya ketika anda tidak ingn Django mengirim surel sama sekali. Sebagai contoh, selagi mengembangkan sebuah situs jaringan, anda mungkin tidak ingin mengirim ribuan surel -- tetapi anda mungkin ingin mensahkan surel akan dikirim ke orang benar dibawah suasana yang benar, dan surel itu akan mengandung isi benar.</p>\n<p>The easiest way to configure email for local development is to use the\n<a class=\"reference internal\" href=\"#topic-email-console-backend\"><span class=\"std std-ref\">console</span></a> email backend. This backend\nredirects all email to <code class=\"docutils literal notranslate\">stdout</code>, allowing you to inspect the content of mail.</p>\n<p>Backend surel <a class=\"reference internal\" href=\"#topic-email-file-backend\"><span class=\"std std-ref\">file</span></a> dapat berguna selama pengembangan -- backend ini membuang isi dari setiap hubungan SMTP ke sebuah berkas yang dapat diperiksa pada waktu luang anda.</p>\n<p>Another approach is to use a &quot;dumb&quot; 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 the <a class=\"reference internal\" href=\"/id/6.0/ref/settings/#std-setting-EMAIL_HOST\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_HOST</code></a> and\n<a class=\"reference internal\" href=\"/id/6.0/ref/settings/#std-setting-EMAIL_PORT\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_PORT</code></a> accordingly. For a more detailed discussion of SMTP\nserver options, see the documentation of the <a class=\"reference external\" href=\"https://aiosmtpd.readthedocs.io/en/latest/\">aiosmtpd</a> module.</p>\n<p>For information about unit-testing the sending of emails in your application,\nsee the <a class=\"reference internal\" href=\"/id/6.0/topics/testing/tools/#topics-testing-email\"><span class=\"std std-ref\">Layanan surel</span></a> section of the testing documentation.</p>\n</section>","rootId":"module-django.core.mail","toc":[{"title":"Quick examples","anchor":"quick-examples","children":[]},{"title":"send_mail()","anchor":"send-mail","children":[]},{"title":"send_mass_mail()","anchor":"send-mass-mail","children":[{"title":"send_mass_mail() x 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":"Contoh","anchor":"examples","children":[]},{"title":"Mencegah penyuntikan kepala","anchor":"preventing-header-injection","children":[]},{"title":"Kelas EmailMessage","anchor":"the-emailmessage-class","children":[{"title":"Obyek EmailMessage","anchor":"emailmessage-objects","children":[]},{"title":"Mengirim pilihan lain jenis isi","anchor":"sending-alternative-content-types","children":[{"title":"Sending multiple content versions","anchor":"sending-multiple-content-versions","children":[]},{"title":"Updating the default content type","anchor":"updating-the-default-content-type","children":[]}]}]},{"title":"Backend email","anchor":"email-backends","children":[{"title":"Mengambil sebuah instance dari sebuah backend surel.","anchor":"obtaining-an-instance-of-an-email-backend","children":[{"title":"Backend SMTP","anchor":"smtp-backend","children":[]},{"title":"Backend konsol","anchor":"console-backend","children":[]},{"title":"Backend berkas","anchor":"file-backend","children":[]},{"title":"backend di-memory","anchor":"in-memory-backend","children":[]},{"title":"Backend tiruan","anchor":"dummy-backend","children":[]}]},{"title":"Menentukan penyesuaian backend surel","anchor":"defining-a-custom-email-backend","children":[]},{"title":"Mengirim banyak surel","anchor":"sending-multiple-emails","children":[]}]},{"title":"Konfigurasi surel untuk pengembangan","anchor":"configuring-email-for-development","children":[]}],"breadcrumbs":[{"docname":"topics/index","title":"Menggunakan Django","url":"/id/6.0/topics/"}],"prev":{"docname":"topics/signing","title":"Penandatanganan Kriptrograpi","url":"/id/6.0/topics/signing/"},"next":{"docname":"topics/i18n/index","title":"Internasionalisasi dan lokalisasi","url":"/id/6.0/topics/i18n/"},"formats":{"html":"/id/6.0/topics/email/","markdown":"/id/6.0/topics/email.md","json":"/id/6.0/topics/email.json"},"source":"https://github.com/django/django/blob/stable/6.0.x/docs/topics/email.txt","official":"https://docs.djangoproject.com/id/6.0/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"]}