{"title":"Mengirim surel","version":"1.11","locale":"id","docname":"topics/email","url":"/id/1.11/topics/email/","canonical":"https://djangodocs.dev/id/1.11/topics/email/","summary":"Meskipun Python membuat mengirim surel cenderung mudah melalui modul smtplib, Django menyediakan salinan ringan yang membungkusnya.","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>Meskipun Python membuat mengirim surel cenderung mudah melalui modul <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>, Django menyediakan salinan ringan yang membungkusnya. Pembungkus ini disediakan untuk membuat pengiriman surel ekstra cepat, untuk membuatnya mudah mengirim surel selama pengembangan, dan untuk menyediakan dukungan untuk serambi yang tidak dapat menggunakan SMTP.</p>\n<p>Kode tinggal dalam modul <code class=\"docutils literal notranslate\">django.core.mail</code>.</p>\n<section id=\"quick-example\">\n<h2>Contoh cepat<a class=\"heading-anchor\" href=\"#quick-example\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Dalam dua baris:</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=\"s1\">&#39;Subject here&#39;</span><span class=\"p\">,</span>\n    <span class=\"s1\">&#39;Here is the message.&#39;</span><span class=\"p\">,</span>\n    <span class=\"s1\">&#39;from@example.com&#39;</span><span class=\"p\">,</span>\n    <span class=\"p\">[</span><span class=\"s1\">&#39;to@example.com&#39;</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>Surat dikirim menggunakan rumah SMTP dan port ditentukan dalam pengaturan <a class=\"reference internal\" href=\"/id/1.11/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/1.11/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/1.11/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/1.11/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/1.11/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/1.11/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/1.11/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\">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>Cara termudah mengirim surel adalah 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.</p></li>\n<li><p><code class=\"docutils literal notranslate\">recipient_list</code>: A list of strings, each an email address. Each\nmember of <code class=\"docutils literal notranslate\">recipient_list</code> will see the other recipients in the &quot;To:&quot;\nfield of the email message.</p></li>\n<li><p><code class=\"docutils literal notranslate\">fail_silently</code>: Sebuah boolean. Jika itu adalah <code class=\"docutils literal notranslate\">False</code>, <code class=\"docutils literal notranslate\">send_mail</code> akan memunculkan sebuah <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>. Lihat dokumen <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> untuk daftar kemungkinan pengecualian, semua yang merupakan subkelas-subkelas dari <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/1.11/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/1.11/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</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\">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> dan <code class=\"docutils literal notranslate\">auth_password</code> mempunyai fungsi sama seperti dalam <a class=\"reference internal\" href=\"#django.core.mail.send_mail\" title=\"django.core.mail.send_mail\"><code class=\"xref py py-meth docutils literal notranslate\">send_mail()</code></a>.</p>\n<p>Setiap unsur terpisah dari <code class=\"docutils literal notranslate\">datatuple</code> menghasilkan dalam pesan surel terpisah. Seperti dalam <a class=\"reference internal\" href=\"#django.core.mail.send_mail\" title=\"django.core.mail.send_mail\"><code class=\"xref py py-meth docutils literal notranslate\">send_mail()</code></a>, penerima dalam <code class=\"docutils literal notranslate\">recipient_list</code> sama akan semua melihat alamat-alamat lain dalam pesan surel' bidang &quot;To:&quot;.</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><span class=\"s1\">&#39;Subject here&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;Here is the message&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;from@example.com&#39;</span><span class=\"p\">,</span> <span class=\"p\">[</span><span class=\"s1\">&#39;first@example.com&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;other@example.com&#39;</span><span class=\"p\">])</span>\nmessage2 <span class=\"o\">=</span> <span class=\"p\">(</span><span class=\"s1\">&#39;Another Subject&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;Here is another message&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;from@example.com&#39;</span><span class=\"p\">,</span> <span class=\"p\">[</span><span class=\"s1\">&#39;second@test.com&#39;</span><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<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>Perbedaan utama diantara <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> dan <a class=\"reference internal\" href=\"#django.core.mail.send_mail\" title=\"django.core.mail.send_mail\"><code class=\"xref py py-meth docutils literal notranslate\">send_mail()</code></a> adalah bahwa <a class=\"reference internal\" href=\"#django.core.mail.send_mail\" title=\"django.core.mail.send_mail\"><code class=\"xref py py-meth docutils literal notranslate\">send_mail()</code></a> membuka sebuah hubungan ke peladen surel setiap itu dijalankan, selagi <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> menggunakan hubungan tunggal untuk semua pesan-pesannya. Ini membuat <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> sedikit lebih efesien.</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\">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/1.11/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/1.11/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/1.11/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</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\">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/1.11/ref/settings/#std-setting-MANAGERS\"><code class=\"xref std std-setting docutils literal notranslate\">MANAGERS</code></a>.</p>\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=\"s1\">&#39;Subject&#39;</span><span class=\"p\">,</span>\n    <span class=\"s1\">&#39;Message.&#39;</span><span class=\"p\">,</span>\n    <span class=\"s1\">&#39;from@example.com&#39;</span><span class=\"p\">,</span>\n    <span class=\"p\">[</span><span class=\"s1\">&#39;john@example.com&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;jane@example.com&#39;</span><span class=\"p\">],</span>\n<span class=\"p\">)</span>\n</code></pre></div>\n<p>Ini mengirim sebuah pesan ke <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 menerima surel terpisah:</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=\"s1\">&#39;Subject&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;Message.&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;from@example.com&#39;</span><span class=\"p\">,</span> <span class=\"p\">[</span><span class=\"s1\">&#39;john@example.com&#39;</span><span class=\"p\">]),</span>\n    <span class=\"p\">(</span><span class=\"s1\">&#39;Subject&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;Message.&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;from@example.com&#39;</span><span class=\"p\">,</span> <span class=\"p\">[</span><span class=\"s1\">&#39;jane@example.com&#39;</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\">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>Fungsi-fungsi surel Django diuraikan diatas semua dilindungi terhadap suntukan kepala dengan melarang baris baru dalam nilai kepala. Jika ada <code class=\"docutils literal notranslate\">subject</code>, <code class=\"docutils literal notranslate\">from_email</code> atau <code class=\"docutils literal notranslate\">recepient_list</code> mengandung sebuah baris baru (dalam salah satu gaya Unix, Windows, atau Mac), fungsi surel (sebagai contoh <a class=\"reference internal\" href=\"#django.core.mail.send_mail\" title=\"django.core.mail.send_mail\"><code class=\"xref py py-meth docutils literal notranslate\">send_mail()</code></a>) akan memunculkan <code class=\"docutils literal notranslate\">django.core.mail.BadHeaderError</code> (sebuah subkelas dari <code class=\"docutils literal notranslate\">ValueError</code>) dan, karenanya, tidak akan mengirim surel. Itu adalah tanggung jawab anda untuk mengesahkan semua data sebelum melewatkan itu ke fungsi-fungsi surel.</p>\n<p>Jika sebuah <code class=\"docutils literal notranslate\">message</code> mengandung kepala-kepala pada awal dari string, kepala-kepala akan cukup dicetak sebagai bit pertama dari pesan surel.</p>\n<p>Ini adalah sebuah contoh tampilan yang mengambil <code class=\"docutils literal notranslate\">subject</code>, <code class=\"docutils literal notranslate\">message</code> dan <code class=\"docutils literal notranslate\">from_email</code> dari data POST permintaan, mengirim itu ke <a class=\"reference external\" href=\"mailto:admin&#37;&#52;&#48;example&#46;com\">admin<span>&#64;</span>example<span>&#46;</span>com</a> dan mengalihkan ke &quot;/contact/thanks/&quot; ketika itu selesai:</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<span class=\"p\">,</span> BadHeaderError\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<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=\"s1\">&#39;subject&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;&#39;</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=\"s1\">&#39;message&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;&#39;</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=\"s1\">&#39;from_email&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;&#39;</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=\"s1\">&#39;admin@example.com&#39;</span><span class=\"p\">])</span>\n        <span class=\"k\">except</span> BadHeaderError<span class=\"p\">:</span>\n            <span class=\"k\">return</span> HttpResponse<span class=\"p\">(</span><span class=\"s1\">&#39;Invalid header found.&#39;</span><span class=\"p\">)</span>\n        <span class=\"k\">return</span> HttpResponseRedirect<span class=\"p\">(</span><span class=\"s1\">&#39;/contact/thanks/&#39;</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=\"s1\">&#39;Make sure all fields are entered and valid.&#39;</span><span class=\"p\">)</span>\n</code></pre></div>\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-meth docutils literal notranslate\">send_mail()</code></a> and\n<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 thin\nwrappers 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\navailable through the <a class=\"reference internal\" href=\"#django.core.mail.send_mail\" title=\"django.core.mail.send_mail\"><code class=\"xref py py-meth docutils literal notranslate\">send_mail()</code></a> and related\nwrapper functions. If you wish to use advanced features, such as BCC'ed\nrecipients, file attachments, or multi-part email, you'll need to create\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> 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-meth docutils literal notranslate\">send_mail()</code></a> and\nrelated functions were originally the only interface Django provided.\nHowever, the list of parameters they accepted was slowly growing over\ntime. It made sense to move to a more object-oriented design for email\nmessages and retain the original functions only for backwards\ncompatibility.</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\nmessage itself. The <a class=\"reference internal\" href=\"#topic-email-backends\"><span class=\"std std-ref\">email backend</span></a> is then\nresponsible for sending the email.</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 simple\n<code class=\"docutils literal notranslate\">send()</code> method for sending a single email. If you need to send multiple\nmessages, the email 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></dd></dl>\n\n<p>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 is initialized with the\nfollowing parameters (in the given order, if positional arguments are used).\nAll parameters are optional and can be set at any time prior to calling the\n<code class=\"docutils literal notranslate\">send()</code> method.</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>: Alamat pengirim. Kedua bentuk <code class=\"docutils literal notranslate\">fred&#64;example.com</code> dan <code class=\"docutils literal notranslate\">Fred &lt;fred&#64;example.com&gt;</code> adalah sah. Jika dihilangkan, pengaturan <a class=\"reference internal\" href=\"/id/1.11/ref/settings/#std-setting-DEFAULT_FROM_EMAIL\"><code class=\"xref std std-setting docutils literal notranslate\">DEFAULT_FROM_EMAIL</code></a> digunakan.</p></li>\n<li><p><code class=\"docutils literal notranslate\">to</code>: Sebuah list atau tuple dari alamat-alamat penerima.</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\">connection</code>: Sebuah instance backend surel. Gunakan parameter ini jika anda ingin menggunakan hubungan sama untuk banyak pesan-pesan. Jika dihilangkan, hubungan baru dibuat ketika <code class=\"docutils literal notranslate\">send()</code> dipanggil.</p></li>\n<li><p><code class=\"docutils literal notranslate\">attachments</code>: Sebuah list atau tuple dari lampiran-lampiran untuk ditaruh pada pesan. Ini dapat salah satu instance <code class=\"docutils literal notranslate\">email.MIMEBase.MIMEBase`, atau ``(filename, content, mimetype)</code> tiga kali lipat.</p></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\">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\">reply_to</code>: Sebuah list atau tuple dari alamat-alamat penerima dalam kepala &quot;Reply-To&quot; ketika mengirim surel.</p></li>\n</ul>\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    <span class=\"s1\">&#39;Hello&#39;</span><span class=\"p\">,</span>\n    <span class=\"s1\">&#39;Body goes here&#39;</span><span class=\"p\">,</span>\n    <span class=\"s1\">&#39;from@example.com&#39;</span><span class=\"p\">,</span>\n    <span class=\"p\">[</span><span class=\"s1\">&#39;to1@example.com&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;to2@example.com&#39;</span><span class=\"p\">],</span>\n    <span class=\"p\">[</span><span class=\"s1\">&#39;bcc@example.com&#39;</span><span class=\"p\">],</span>\n    reply_to<span class=\"o\">=</span><span class=\"p\">[</span><span class=\"s1\">&#39;another@example.com&#39;</span><span class=\"p\">],</span>\n    headers<span class=\"o\">=</span><span class=\"p\">{</span><span class=\"s1\">&#39;Message-ID&#39;</span><span class=\"p\">:</span> <span class=\"s1\">&#39;foo&#39;</span><span class=\"p\">},</span>\n<span class=\"p\">)</span>\n</code></pre></div>\n<p>Kelas mempunyai cara berikut:</p>\n<ul>\n<li><p><code class=\"docutils literal notranslate\">send(fail_silently=False)</code> sends the message. If a connection was\nspecified when the email was constructed, that connection will be used.\nOtherwise, an instance of the default backend will be instantiated and\nused. If the keyword argument <code class=\"docutils literal notranslate\">fail_silently</code> is <code class=\"docutils literal notranslate\">True</code>, exceptions\nraised while sending the message will be quashed. An empty list of\nrecipients will not raise an exception.</p></li>\n<li><p><code class=\"docutils literal notranslate\">message()</code> constructs a <code class=\"docutils literal notranslate\">django.core.mail.SafeMIMEText</code> object (a\nsubclass of Python's <code class=\"docutils literal notranslate\">email.MIMEText.MIMEText</code> class) or a\n<code class=\"docutils literal notranslate\">django.core.mail.SafeMIMEMultipart</code> object holding the message to be\nsent. If you ever need to extend the\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> class, you'll probably want to\noverride this method to put the content you want into the MIME object.</p></li>\n<li><p><code class=\"docutils literal notranslate\">recipients()</code> returns a list of all the recipients of the message,\nwhether they're recorded 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\nis another method you might need to override when subclassing, because the\nSMTP server 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, they\nneed to be returned from this method as well.</p></li>\n<li><p><code class=\"docutils literal notranslate\">attach()</code> membuat lampiran berkas baru dan menambahkan itu ke pesan. Ada dua cara memanggil <code class=\"docutils literal notranslate\">attach()</code>:</p>\n<ul>\n<li><p>Anda dapat melewatkan itu sebuah argumen tunggal yaitu sebuah instance <code class=\"docutils literal notranslate\">email.MIMEBase.MIMEBase</code>. Ini akan dimasukkan langsung kedalam hasil pesan.</p></li>\n<li><p>Alternatively, you can pass <code class=\"docutils literal notranslate\">attach()</code> three arguments:\n<code class=\"docutils literal notranslate\">filename</code>, <code class=\"docutils literal notranslate\">content</code> and <code class=\"docutils literal notranslate\">mimetype</code>. <code class=\"docutils literal notranslate\">filename</code> is the name\nof the file attachment as it will appear in the email, <code class=\"docutils literal notranslate\">content</code> is\nthe data that will be contained inside the attachment and\n<code class=\"docutils literal notranslate\">mimetype</code> is the optional MIME type for the attachment. If you\nomit <code class=\"docutils literal notranslate\">mimetype</code>, the MIME content type will be guessed from the\nfilename 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=\"s1\">&#39;design.png&#39;</span><span class=\"p\">,</span> img_data<span class=\"p\">,</span> <span class=\"s1\">&#39;image/png&#39;</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>Jika anda menentukan <code class=\"docutils literal notranslate\">mimetype</code> dari <code class=\"docutils literal notranslate\">message/rfc822</code>, itu juga akan menerima <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> dan <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>Untuk <code class=\"docutils literal notranslate\">mimetype</code> dimulai dengan <code class=\"docutils literal notranslate\">text/</code>, konteks diharapkan berupa string. Data biner akan disandikan menggunakan UTF-8, dan jka itu gagal, jenis MIME akan dirubah menjadi <code class=\"docutils literal notranslate\">application/octet-stream</code> dan data akan dilampirkan tidak berubah.</p>\n<p>Sebagai tambahan, lampiran-lampiran <code class=\"docutils literal notranslate\">message/rfc822</code> tidak lama lagi berupa disandi-base64 dalam pelanggaran dari <span class=\"target\" id=\"index-2\"></span><a class=\"rfc reference external\" href=\"https://datatracker.ietf.org/doc/html/rfc2046.html#section-5.2.1\"><strong>RFC 2046 Section 5.2.1</strong></a>, yang dapat menyebabkan masalah-masalah dengan menampilkan lampiran dalam <a class=\"reference external\" href=\"https://bugzilla.gnome.org/show_bug.cgi?id=651197\">Evolution</a> dan <a class=\"reference external\" href=\"https://bugzilla.mozilla.org/show_bug.cgi?id=333880\">Thunderbird</a>.</p>\n</li>\n</ul>\n</li>\n<li><p><code class=\"docutils literal notranslate\">attach_file()</code> creates a new attachment using a file from your\nfilesystem. Call it with the path of the file to attach and, optionally,\nthe MIME type to use for the attachment. If the MIME type is omitted, it\nwill be guessed from the filename. The simplest use would be:</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=\"s1\">&#39;/images/weather_map.png&#39;</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>Untuk jenis-jenis MIME dimulai dengan <code class=\"docutils literal notranslate\">text/</code>, data biner ditangani dalam <code class=\"docutils literal notranslate\">attach()</code>.</p>\n</li>\n</ul>\n<aside class=\"version-note version-changed\" data-version=\"1.11\" role=\"note\">\n<p class=\"version-note-title\">Changed in Django 1.11</p><p>Added the fallback to MIME type <code class=\"docutils literal notranslate\">application/octet-stream</code> when binary\ndata for a <code class=\"docutils literal notranslate\">text/*</code> attachment cannot be decoded.</p>\n</aside>\n<section id=\"sending-alternative-content-types\">\n<h4>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></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 <code class=\"docutils literal notranslate\">EmailMultiAlternatives</code>\nclass. This 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> has an\n<code class=\"docutils literal notranslate\">attach_alternative()</code> method for including extra versions of the message\nbody in the email. All the other methods (including the class initialization)\nare inherited directly from <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<p>Untuk mengirim perpaduan teks dan HTML, anda dapat menulis:</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=\"p\">,</span> from_email<span class=\"p\">,</span> to <span class=\"o\">=</span> <span class=\"s1\">&#39;hello&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;from@example.com&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;to@example.com&#39;</span>\ntext_content <span class=\"o\">=</span> <span class=\"s1\">&#39;This is an important message.&#39;</span>\nhtml_content <span class=\"o\">=</span> <span class=\"s1\">&#39;&lt;p&gt;This is an &lt;strong&gt;important&lt;/strong&gt; message.&lt;/p&gt;&#39;</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<p>By default, the MIME type of the <code class=\"docutils literal notranslate\">body</code> parameter in an\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> is <code class=\"docutils literal notranslate\">&quot;text/plain&quot;</code>. It is good\npractice to leave this alone, because it guarantees that any recipient will be\nable to read the email, regardless of their mail client. However, if you are\nconfident that your recipients can handle an alternative content type, you can\nuse the <code class=\"docutils literal notranslate\">content_subtype</code> attribute on the\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> 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\nsubtype. 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>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\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> objects. If the connection is\nnot open, this call will implicitly open the connection, and close the\nconnection afterwards. If the connection is already open, it will be\nleft 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> body1<span class=\"p\">,</span> from1<span class=\"p\">,</span> <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> body2<span class=\"p\">,</span> from2<span class=\"p\">,</span> <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>Fungsi <a class=\"reference internal\" href=\"#django.core.mail.get_connection\" title=\"django.core.mail.get_connection\"><code class=\"xref py py-meth docutils literal notranslate\">get_connection()</code></a> dalam <code class=\"docutils literal notranslate\">django.core.mail</code> mengembalikan sebuah instance dari backend surel yang anda dapat gunakan.</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\">fail_silently<span class=\"o\">=</span><span class=\"default_value\">False</span></em>, <em class=\"sig-param\"><span class=\"o\">*</span>args</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>By default, a call to <code class=\"docutils literal notranslate\">get_connection()</code> will return an instance of the\nemail backend specified in <a class=\"reference internal\" href=\"/id/1.11/ref/settings/#std-setting-EMAIL_BACKEND\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_BACKEND</code></a>. If you specify the\n<code class=\"docutils literal notranslate\">backend</code> argument, an instance of that backend will be instantiated.</p>\n<p>The <code class=\"docutils literal notranslate\">fail_silently</code> argument controls how the backend should handle errors.\nIf <code class=\"docutils literal notranslate\">fail_silently</code> is True, exceptions during the email sending process\nwill be silently ignored.</p>\n<p>Semua argumen lain dilewatkan langsung ke pembangun dari backend surel.</p>\n<p>Django ships with several email sending backends. With the exception of the\nSMTP backend (which is the default), these backends are only useful during\ntesting and development. If you have special email sending requirements, you\ncan <a class=\"reference internal\" href=\"#topic-custom-email-backend\"><span class=\"std std-ref\">write your own email backend</span></a>.</p>\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/1.11/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/1.11/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/1.11/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/1.11/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/1.11/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/1.11/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/1.11/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/1.11/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/1.11/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=\"s1\">&#39;django.core.mail.backends.smtp.EmailBackend&#39;</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>Instead of sending out real emails the console backend just writes the\nemails that would be sent to the standard output. By default, the console\nbackend writes to <code class=\"docutils literal notranslate\">stdout</code>. You can use a different stream-like object by\nproviding the <code class=\"docutils literal notranslate\">stream</code> keyword argument when constructing the connection.</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=\"s1\">&#39;django.core.mail.backends.console.EmailBackend&#39;</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/1.11/ref/settings/#std-setting-EMAIL_FILE_PATH\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_FILE_PATH</code></a> setting or from\nthe <code class=\"docutils literal notranslate\">file_path</code> keyword when creating a connection with\n<a class=\"reference internal\" href=\"#django.core.mail.get_connection\" title=\"django.core.mail.get_connection\"><code class=\"xref py py-meth 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=\"s1\">&#39;django.core.mail.backends.filebased.EmailBackend&#39;</span>\nEMAIL_FILE_PATH <span class=\"o\">=</span> <span class=\"s1\">&#39;/tmp/app-messages&#39;</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>In-memory backend<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\nfirst message is sent. It's a list with an\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> instance for each message that would\nbe 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=\"s1\">&#39;django.core.mail.backends.locmem.EmailBackend&#39;</span>\n</code></pre></div>\n<p>This backend is not intended for use in production -- it is provided as a\nconvenience that can be used during development and testing.</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>As the name suggests the dummy backend does nothing with your messages. To\nspecify this backend, put the following in your settings:</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=\"s1\">&#39;django.core.mail.backends.dummy.EmailBackend&#39;</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>\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>If you need to change how emails are sent you can write your own email\nbackend. The <a class=\"reference internal\" href=\"/id/1.11/ref/settings/#std-setting-EMAIL_BACKEND\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_BACKEND</code></a> setting in your settings file is then\nthe Python import path for your backend class.</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\nnumber of successfully delivered messages. If your backend has any concept of\na persistent session or connection, you should also implement the <code class=\"docutils literal notranslate\">open()</code>\nand <code class=\"docutils literal notranslate\">close()</code> methods. Refer to <code class=\"docutils literal notranslate\">smtp.EmailBackend</code> for a reference\nimplementation.</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>Establishing and closing an SMTP connection (or any other network connection,\nfor that matter) is an expensive process. If you have a lot of emails to send,\nit makes sense to reuse an SMTP connection, rather than creating and\ndestroying a connection every time you want to send an email.</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. <code class=\"docutils literal notranslate\">send_messages()</code> 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> instances (or subclasses),\nand sends them all using a single connection.</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\nsome periodic email you wish to send out, you could send these emails using\na single call to send_messages:</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\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>The second approach is to use the <code class=\"docutils literal notranslate\">open()</code> and <code class=\"docutils literal notranslate\">close()</code> methods on the\nemail backend to manually control the connection. <code class=\"docutils literal notranslate\">send_messages()</code> will not\nmanually open or close the connection if it is already open, so if you\nmanually open the connection, you can control when it is closed. For example:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.core</span> <span class=\"kn\">import</span> mail\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=\"s1\">&#39;Hello&#39;</span><span class=\"p\">,</span>\n    <span class=\"s1\">&#39;Body goes here&#39;</span><span class=\"p\">,</span>\n    <span class=\"s1\">&#39;from@example.com&#39;</span><span class=\"p\">,</span>\n    <span class=\"p\">[</span><span class=\"s1\">&#39;to1@example.com&#39;</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=\"s1\">&#39;Hello&#39;</span><span class=\"p\">,</span>\n    <span class=\"s1\">&#39;Body goes here&#39;</span><span class=\"p\">,</span>\n    <span class=\"s1\">&#39;from@example.com&#39;</span><span class=\"p\">,</span>\n    <span class=\"p\">[</span><span class=\"s1\">&#39;to2@example.com&#39;</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=\"s1\">&#39;Hello&#39;</span><span class=\"p\">,</span>\n    <span class=\"s1\">&#39;Body goes here&#39;</span><span class=\"p\">,</span>\n    <span class=\"s1\">&#39;from@example.com&#39;</span><span class=\"p\">,</span>\n    <span class=\"p\">[</span><span class=\"s1\">&#39;to3@example.com&#39;</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>There are times when you do not want Django to send emails at\nall. For example, while developing a website, you probably don't want\nto send out thousands of emails -- but you may want to validate that\nemails will be sent to the right people under the right conditions,\nand that those emails will contain the correct content.</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 stdout, allowing you to inspect the content of mail.</p>\n<p>The <a class=\"reference internal\" href=\"#topic-email-file-backend\"><span class=\"std std-ref\">file</span></a> email backend can also be useful\nduring development -- this backend dumps the contents of every SMTP connection\nto a file that can be inspected at your leisure.</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. Python has a built-in way to accomplish this with a single command:</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>python <span class=\"o\">-</span>m smtpd <span class=\"o\">-</span>n <span class=\"o\">-</span>c DebuggingServer localhost<span class=\"p\">:</span><span class=\"mi\">1025</span>\n</code></pre></div>\n<p>This command will start a simple SMTP server listening on port 1025 of\nlocalhost. This server simply prints to standard output all email headers and\nthe email body. You then only need to set the <a class=\"reference internal\" href=\"/id/1.11/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/1.11/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 Python documentation for the <a class=\"reference external\" href=\"https://docs.python.org/3/library/smtpd.html#module-smtpd\" title=\"(di Python v3.14)\"><code class=\"xref py py-mod docutils literal notranslate\">smtpd</code></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/1.11/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":"Contoh cepat","anchor":"quick-example","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":"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":"In-memory backend","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/1.11/topics/"}],"prev":{"docname":"topics/signing","title":"Penandatanganan Kriptrograpi","url":"/id/1.11/topics/signing/"},"next":{"docname":"topics/i18n/index","title":"Internasionalisasi dan lokalisasi","url":"/id/1.11/topics/i18n/"},"formats":{"html":"/id/1.11/topics/email/","markdown":"/id/1.11/topics/email.md","json":"/id/1.11/topics/email.json"},"source":"https://github.com/django/django/blob/stable/1.11.x/docs/topics/email.txt","official":"https://docs.djangoproject.com/id/1.11/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","fr","ja","id","pt-br","ko","es","el","pl"]}