{"title":"Migration des réglages de messagerie vers le système des envois","version":"6.1","locale":"fr","docname":"howto/mailers-migration","url":"/fr/6.1/howto/mailers-migration/","canonical":"https://djangodocs.dev/fr/6.1/howto/mailers-migration/","summary":"Django 6.1 introduit le réglage MAILERS, remplaçant EMAIL_BACKEND et plusieurs autres réglages EMAIL_*.","html":"<span id=\"migrating-to-mailers\"></span><h1>Migration des réglages de messagerie vers le système des envois<a class=\"heading-anchor\" href=\"#migrating-email-to-mailers\"><span class=\"visually-hidden\">Lien vers cette rubrique</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>Django 6.1 introduit le réglage <a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a>, remplaçant <a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-EMAIL_BACKEND\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_BACKEND</code></a> et plusieurs autres réglages <code class=\"docutils literal notranslate\">EMAIL_*</code>. Il introduit également <a class=\"reference internal\" href=\"/fr/6.1/topics/email/#django.core.mail.mailers\" title=\"django.core.mail.mailers\"><code class=\"xref py py-data docutils literal notranslate\">mail.mailers</code></a> pour l’obtention d’instances de moteurs de messagerie configurés, remplaçant <a class=\"reference internal\" href=\"/fr/6.1/topics/email/#django.core.mail.get_connection\" title=\"django.core.mail.get_connection\"><code class=\"xref py py-func docutils literal notranslate\">mail.get_connection()</code></a>. Un nouvel argument <code class=\"docutils literal notranslate\">using</code> remplace l’ancien argument <code class=\"docutils literal notranslate\">connection</code> dans les fonctions Django qui envoient des courriels.</p>\n<p>Ce guide fournit des détails sur la migration de projets existants vers la nouvelle fonctionnalité du système des envois.</p>\n<p>Tous les projets Django qui envoient des courriels devraient :</p>\n<ul>\n<li><p>Si des paquets externes sont utilisés pour envoyer des messages, <a class=\"reference internal\" href=\"#migrating-to-mailers-third-party\"><span class=\"std std-ref\">vérifier leur compatibilité</span></a> avec <a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> avant de faire d’autres changements.</p></li>\n<li><p><a class=\"reference internal\" href=\"#migrating-to-mailers-settings\"><span class=\"std std-ref\">Mettre à jour les réglages liés à la messagerie</span></a>.</p></li>\n<li><p>S’exécuter avec les avertissements d’obsolescence activés (voir <a class=\"reference internal\" href=\"/fr/6.1/howto/upgrade-version/#resolving-deprecation-warnings\"><span class=\"std std-ref\">Résolution des avertissements d’obsolescence</span></a>) pour identifier les parties de code nécessitant une mise à jour.</p>\n<aside class=\"admonition admonition-note\" role=\"note\">\n<p class=\"admonition-title\">Note</p>\n<p>Le lancement des tests ne révèle pas toujours tous les endroits à mettre à jour. Les suites de test utilisent fréquemment un moteur de messagerie non fonctionnel (tel que le moteur basé en mémoire que Django <a class=\"reference internal\" href=\"/fr/6.1/topics/testing/tools/#topics-testing-email\"><span class=\"std std-ref\">utilise durant les tests</span></a>), et peuvent donc manquer des avertissements d’obsolescence qui ne sont déclenchés qu’avec une configuration de messagerie en production.</p>\n<p>Consider running with deprecation warnings enabled in production to catch\nthose deprecations. Or carefully review your code (including third-party\npackages) for use of any deprecated email features.</p>\n</aside>\n</li>\n</ul>\n<p>D’autres mises à jour ne sont nécessaires que pour des projets ou des bibliothèques Django réutilisables qui utilisent ces fonctionnalités spécifiques :</p>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"#migrating-to-mailers-get-connection\"><span class=\"std std-ref\">Replacing get_connection() and connection arguments</span></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#migrating-to-mailers-fail-silently\"><span class=\"std std-ref\">Replacing fail_silently</span></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#migrating-to-mailers-email-backends\"><span class=\"std std-ref\">Migrating custom email backends</span></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#migrating-to-mailers-auth\"><span class=\"std std-ref\">Replacing auth_user and auth_password</span></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#migrating-to-mailers-adminemailhandler\"><span class=\"std std-ref\">Updating AdminEmailHandler email_backend</span></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#migrating-to-mailers-error-reporting\"><span class=\"std std-ref\">Ignoring transient failures in error reporting</span></a></p></li>\n</ul>\n<aside class=\"version-note version-deprecated\" data-version=\"6.1\" role=\"note\">\n<p class=\"version-note-title\">Deprecated since Django 6.1</p><p><span class=\"versionmodified deprecated\">Obsolète depuis la version 6.1: </span>Les réglages et fonctions suivantes seront supprimées dans Django 2028 :</p>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-EMAIL_BACKEND\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_BACKEND</code></a>, <a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-EMAIL_FILE_PATH\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_FILE_PATH</code></a>,\n<a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-EMAIL_HOST\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_HOST</code></a>, <a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-EMAIL_HOST_PASSWORD\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_HOST_PASSWORD</code></a>,\n<a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-EMAIL_HOST_USER\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_HOST_USER</code></a>, <a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-EMAIL_PORT\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_PORT</code></a>,\n<a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-EMAIL_SSL_CERTFILE\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_SSL_CERTFILE</code></a>, <a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-EMAIL_SSL_KEYFILE\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_SSL_KEYFILE</code></a>,\n<a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-EMAIL_TIMEOUT\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_TIMEOUT</code></a>, <a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-EMAIL_USE_SSL\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_USE_SSL</code></a>,\n<a class=\"reference internal\" href=\"/fr/6.1/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><a class=\"reference internal\" href=\"/fr/6.1/topics/email/#django.core.mail.get_connection\" title=\"django.core.mail.get_connection\"><code class=\"xref py py-func docutils literal notranslate\">mail.get_connection()</code></a> et les arguements <code class=\"docutils literal notranslate\">connection</code> des fonctions d’envoi de messages</p></li>\n<li><p>L’argument <code class=\"docutils literal notranslate\">fail_silently</code> de <a class=\"reference internal\" href=\"/fr/6.1/topics/email/#django.core.mail.send_mail\" title=\"django.core.mail.send_mail\"><code class=\"xref py py-func docutils literal notranslate\">send_mail()</code></a>, <a class=\"reference internal\" href=\"/fr/6.1/topics/email/#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>, <a class=\"reference internal\" href=\"/fr/6.1/topics/email/#django.core.mail.mail_admins\" title=\"django.core.mail.mail_admins\"><code class=\"xref py py-func docutils literal notranslate\">mail_admins()</code></a>, <a class=\"reference internal\" href=\"/fr/6.1/topics/email/#django.core.mail.mail_managers\" title=\"django.core.mail.mail_managers\"><code class=\"xref py py-func docutils literal notranslate\">mail_managers()</code></a> et <a class=\"reference internal\" href=\"/fr/6.1/topics/email/#django.core.mail.EmailMessage.send\" title=\"django.core.mail.EmailMessage.send\"><code class=\"xref py py-meth docutils literal notranslate\">EmailMessage.send()</code></a></p></li>\n<li><p>Les arguments <code class=\"docutils literal notranslate\">auth_user</code> et <code class=\"docutils literal notranslate\">auth_password</code> de <a class=\"reference internal\" href=\"/fr/6.1/topics/email/#django.core.mail.send_mail\" title=\"django.core.mail.send_mail\"><code class=\"xref py py-func docutils literal notranslate\">send_mail()</code></a> et <a class=\"reference internal\" href=\"/fr/6.1/topics/email/#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></p></li>\n<li><p>L’argument <code class=\"docutils literal notranslate\">email_backend</code> de <a class=\"reference internal\" href=\"/fr/6.1/ref/logging/#django.utils.log.AdminEmailHandler\" title=\"django.utils.log.AdminEmailHandler\"><code class=\"xref py py-class docutils literal notranslate\">AdminEmailHandler</code></a></p></li>\n</ul>\n</aside>\n<section id=\"migrating-settings\">\n<span id=\"migrating-to-mailers-settings\"></span><h2>Migration des réglages<a class=\"heading-anchor\" href=\"#migrating-settings\"><span class=\"visually-hidden\">Lien vers cette rubrique</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Souvent, le seul changement nécessaire pour migrer vers le nouveau style de configuration de messagerie est de mettre à jour les réglages liés à la messagerie. Dans les réglages de votre projet, définissez un dictionnaire <a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> avec une clé <code class=\"docutils literal notranslate\">&quot;default&quot;</code> correspondant aux anciens réglages <code class=\"docutils literal notranslate\">EMAIL_*</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>MAILERS <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;default&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;BACKEND&quot;</span><span class=\"p\">:</span> <span class=\"o\">...</span><span class=\"p\">,</span>  <span class=\"c1\"># value of EMAIL_BACKEND setting</span>\n        <span class=\"s2\">&quot;OPTIONS&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"c1\"># values from other deprecated EMAIL_* settings</span>\n            <span class=\"o\">...</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p>Par exemple, pour mettre à jour ces réglages :</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>\nEMAIL_HOST <span class=\"o\">=</span> <span class=\"s2\">&quot;mail.example.net&quot;</span>\nEMAIL_USE_TLS <span class=\"o\">=</span> <span class=\"kc\">True</span>\nEMAIL_PORT <span class=\"o\">=</span> <span class=\"mi\">587</span>\nEMAIL_HOST_USER <span class=\"o\">=</span> <span class=\"s2\">&quot;user@example.net&quot;</span>\nEMAIL_HOST_PASSWORD <span class=\"o\">=</span> <span class=\"s2\">&quot;password&quot;</span>\n</code></pre></div>\n<p>utilisez :</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>MAILERS <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;default&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;BACKEND&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.core.mail.backends.smtp.EmailBackend&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;OPTIONS&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;host&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;mail.example.net&quot;</span><span class=\"p\">,</span>\n            <span class=\"s2\">&quot;use_tls&quot;</span><span class=\"p\">:</span> <span class=\"kc\">True</span><span class=\"p\">,</span>\n            <span class=\"c1\"># port is not needed: it defaults to 587 with use_tls True.</span>\n            <span class=\"s2\">&quot;username&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;user@example.net&quot;</span><span class=\"p\">,</span>\n            <span class=\"s2\">&quot;password&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;password&quot;</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p id=\"deprecated-email-settings\">La liste complète des réglages <code class=\"docutils literal notranslate\">EMAIL_*</code> obsolètes et l’endroit vers lequel ils devraient être déplacés dans une configuration <a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> se trouve ici :</p>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-EMAIL_BACKEND\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_BACKEND</code></a> becomes <code class=\"docutils literal notranslate\">&quot;BACKEND&quot;</code>. If your settings didn’t\ndefine <code class=\"xref std std-setting docutils literal notranslate\">EMAIL_BACKEND</code>, the default value was\n<code class=\"docutils literal notranslate\">&quot;django.core.mail.backends.smtp.EmailBackend&quot;</code> (which is also the default\nif a <a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> configuration doesn’t specify the <code class=\"docutils literal notranslate\">&quot;BACKEND&quot;</code>).</p></li>\n<li><p><a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-EMAIL_FILE_PATH\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_FILE_PATH</code></a> becomes <code class=\"docutils literal notranslate\">&quot;file_path&quot;</code> in <code class=\"docutils literal notranslate\">&quot;OPTIONS&quot;</code> (with\n<code class=\"docutils literal notranslate\">&quot;BACKEND&quot;</code> set to <code class=\"docutils literal notranslate\">&quot;django.core.mail.backends.filebased.EmailBackend&quot;</code>).</p></li>\n<li><p><a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-EMAIL_HOST\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_HOST</code></a> becomes <code class=\"docutils literal notranslate\">&quot;host&quot;</code> in <code class=\"docutils literal notranslate\">&quot;OPTIONS&quot;</code>. A <code class=\"docutils literal notranslate\">&quot;host&quot;</code> is\nrequired for the SMTP email backend. If your settings didn’t define\n<code class=\"docutils literal notranslate\">EMAIL_HOST</code>, set <code class=\"docutils literal notranslate\">&quot;host&quot;</code> to <code class=\"docutils literal notranslate\">&quot;localhost&quot;</code> (the default value for the\ndeprecated setting).</p></li>\n<li><p><a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-EMAIL_HOST_PASSWORD\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_HOST_PASSWORD</code></a> devient <code class=\"docutils literal notranslate\">&quot;password&quot;</code> dans <code class=\"docutils literal notranslate\">&quot;OPTIONS&quot;</code>.</p></li>\n<li><p><a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-EMAIL_HOST_USER\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_HOST_USER</code></a> devient <code class=\"docutils literal notranslate\">&quot;username&quot;</code> dans <code class=\"docutils literal notranslate\">&quot;OPTIONS&quot;</code> (notez que <code class=\"docutils literal notranslate\">&quot;username&quot;</code> ne suit pas strictement le schéma de renommage des autres réglages obsolètes).</p></li>\n<li><p><a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-EMAIL_PORT\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_PORT</code></a> devient <code class=\"docutils literal notranslate\">&quot;port&quot;</code> dans <code class=\"docutils literal notranslate\">&quot;OPTIONS&quot;</code>. Il peut être omis si la connexion utilise le port par défaut pour sa sécurité (465 pour SSL, 587 pour TLS, ou 25 pour une connexion SMTP non sécurisée).</p></li>\n<li><p><a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-EMAIL_SSL_CERTFILE\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_SSL_CERTFILE</code></a> devient <code class=\"docutils literal notranslate\">&quot;ssl_certfile&quot;</code> dans <code class=\"docutils literal notranslate\">&quot;OPTIONS&quot;</code>.</p></li>\n<li><p><a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-EMAIL_SSL_KEYFILE\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_SSL_KEYFILE</code></a> devient <code class=\"docutils literal notranslate\">&quot;ssl_keyfile&quot;</code> dans <code class=\"docutils literal notranslate\">&quot;OPTIONS&quot;</code>.</p></li>\n<li><p><a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-EMAIL_TIMEOUT\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_TIMEOUT</code></a> devient <code class=\"docutils literal notranslate\">&quot;timeout&quot;</code> dans <code class=\"docutils literal notranslate\">&quot;OPTIONS&quot;</code>.</p></li>\n<li><p><a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-EMAIL_USE_SSL\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_USE_SSL</code></a> devient <code class=\"docutils literal notranslate\">&quot;use_ssl&quot;</code> dans <code class=\"docutils literal notranslate\">&quot;OPTIONS&quot;</code>.</p></li>\n<li><p><a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-EMAIL_USE_TLS\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_USE_TLS</code></a> devient <code class=\"docutils literal notranslate\">&quot;use_tls&quot;</code> dans <code class=\"docutils literal notranslate\">&quot;OPTIONS&quot;</code>.</p></li>\n</ul>\n<p>For third-party or custom email backends, the available <code class=\"docutils literal notranslate\">&quot;OPTIONS&quot;</code> depend on\nthe backend. Refer to the third-party documentation, or for custom backends see\n<a class=\"reference internal\" href=\"#migrating-to-mailers-email-backends\"><span class=\"std std-ref\">Migrating custom email backends</span></a> below.</p>\n<p>The <a class=\"reference internal\" href=\"/fr/6.1/topics/email/#topic-email-configuration\"><span class=\"std std-ref\">Configuring email</span></a> topic has more information on the\n<code class=\"docutils literal notranslate\">MAILERS</code> setting and additional configuration examples.</p>\n</section>\n<section id=\"reusable-library-readiness\">\n<span id=\"migrating-to-mailers-third-party\"></span><h2>Reusable library readiness<a class=\"heading-anchor\" href=\"#reusable-library-readiness\"><span class=\"visually-hidden\">Lien vers cette rubrique</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>In most cases, third-party packages that send email through Django will\ncontinue working with projects whose settings have been upgraded to use\n<a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a>. (If they use any deprecated mail features, those will of\ncourse cause deprecation warnings.)</p>\n<p>There are two deprecated features that are <em>not</em> supported when\n<a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> is defined in a project’s settings:</p>\n<ul class=\"simple\">\n<li><p>Trying to access any of the deprecated <code class=\"docutils literal notranslate\">EMAIL_*</code> settings on\n<code class=\"docutils literal notranslate\">django.conf.settings</code> (e.g., checking <code class=\"docutils literal notranslate\">settings.EMAIL_BACKEND</code> or using\n<code class=\"docutils literal notranslate\">settings.EMAIL_HOST_USER</code>).</p></li>\n<li><p>Calling <a class=\"reference internal\" href=\"/fr/6.1/topics/email/#django.core.mail.get_connection\" title=\"django.core.mail.get_connection\"><code class=\"xref py py-func docutils literal notranslate\">mail.get_connection(&quot;path.to.EmailBackend&quot;)</code></a> with a specific backend path. (Other arguments to\n<code class=\"docutils literal notranslate\">get_connection()</code> are still supported, and will simply issue deprecation\nwarnings when <a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> is defined.)</p></li>\n</ul>\n<p>If a third-party package does either of those, projects that use it will not be\nable to change to the <a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> setting until the package has been\nupdated.</p>\n<section id=\"solving-not-available-when-mailers-is-defined-errors\">\n<h3>Solving « not available when MAILERS is defined » errors<a class=\"heading-anchor\" href=\"#solving-not-available-when-mailers-is-defined-errors\"><span class=\"visually-hidden\">Lien vers cette rubrique</span><span aria-hidden=\"true\">#</span></a></h3>\n<p>If either of these errors are raised within a third-party package, that\nindicates it is not compatible with the <a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> setting:</p>\n<ul class=\"simple\">\n<li><p><code class=\"samp docutils literal notranslate\">AttributeError: &quot;The <em>name</em> setting is not available when MAILERS is\ndefined&quot;</code> where <em>name</em> is <a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-EMAIL_BACKEND\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_BACKEND</code></a>, <a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-EMAIL_HOST\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_HOST</code></a>,\nor one of the other deprecated settings.</p></li>\n<li><p><code class=\"docutils literal notranslate\">RuntimeError: get_connection(backend, ...) is not supported with MAILERS.</code></p></li>\n</ul>\n<p>If you see these errors, check if a newer version of that dependency is\navailable. If not (and if there are no alternatives to that package), you will\nneed to remove <a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> from your settings and replace it with the\nequivalent <a class=\"reference internal\" href=\"#deprecated-email-settings\"><span class=\"std std-ref\">deprecated email settings</span></a> until\nthe package has been updated.</p>\n<p>If those errors are coming from your own code, see the other sections in this\nmigration guide for recommended updates.</p>\n</section>\n</section>\n<section id=\"replacing-get-connection-and-connection-arguments\">\n<span id=\"migrating-to-mailers-get-connection\"></span><h2>Replacing <code class=\"docutils literal notranslate\">get_connection()</code> and <code class=\"docutils literal notranslate\">connection</code> arguments<a class=\"heading-anchor\" href=\"#replacing-get-connection-and-connection-arguments\"><span class=\"visually-hidden\">Lien vers cette rubrique</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>The replacements for the deprecated <a class=\"reference internal\" href=\"/fr/6.1/topics/email/#django.core.mail.get_connection\" title=\"django.core.mail.get_connection\"><code class=\"xref py py-func docutils literal notranslate\">mail.get_connection()</code></a> function\nand <code class=\"docutils literal notranslate\">connection</code> arguments to other mail functions depend on how and why\nthe connections are being created:</p>\n<ul>\n<li><p><code class=\"docutils literal notranslate\">get_connection()</code> called with no arguments</p>\n<p>Replace with <a class=\"reference internal\" href=\"/fr/6.1/topics/email/#django.core.mail.mailers.default\" title=\"django.core.mail.mailers.default\"><code class=\"xref py py-data docutils literal notranslate\">mailers.default</code></a>. For example, update this 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>connection <span class=\"o\">=</span> mail<span class=\"o\">.</span>get_connection<span class=\"p\">()</span>\nconnection<span class=\"o\">.</span>send_messages<span class=\"p\">([</span>email1<span class=\"p\">,</span> email2<span class=\"p\">])</span>\n</code></pre></div>\n<p>To:</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>connection <span class=\"o\">=</span> mail<span class=\"o\">.</span>mailers<span class=\"o\">.</span>default\nconnection<span class=\"o\">.</span>send_messages<span class=\"p\">([</span>email1<span class=\"p\">,</span> email2<span class=\"p\">])</span>\n</code></pre></div>\n<p>Note that <code class=\"docutils literal notranslate\">mailers.default</code> <em>is</em> the default for Django’s mail-sending\nfunctions. Code 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>mail<span class=\"o\">.</span>send_mail<span class=\"p\">(</span><span class=\"o\">...</span><span class=\"p\">,</span> connection<span class=\"o\">=</span>mail<span class=\"o\">.</span>get_connection<span class=\"p\">())</span>\n</code></pre></div>\n<p>can be updated to:</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>mail<span class=\"o\">.</span>send_mail<span class=\"p\">(</span><span class=\"o\">...</span><span class=\"p\">)</span>  <span class=\"c1\"># No connection arg needed.</span>\n</code></pre></div>\n</li>\n<li><p><code class=\"docutils literal notranslate\">get_connection(fail_silently=True)</code></p>\n<p>See <a class=\"reference internal\" href=\"#migrating-to-mailers-fail-silently\"><span class=\"std std-ref\">Replacing fail_silently</span></a>.</p>\n</li>\n<li><p><code class=\"docutils literal notranslate\">get_connection(...)</code> called with any other arguments</p>\n<p>Define a custom <a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> configuration with the desired backend\nand options. Then refer to it in the <code class=\"docutils literal notranslate\">using</code> argument when sending mail,\nor obtain an email backend instance from <a class=\"reference internal\" href=\"/fr/6.1/topics/email/#django.core.mail.mailers\" title=\"django.core.mail.mailers\"><code class=\"xref py py-data docutils literal notranslate\">mail.mailers</code></a> with the\nconfiguration name.</p>\n<p>For example, to upgrade this 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>connection <span class=\"o\">=</span> mail<span class=\"o\">.</span>get_connection<span class=\"p\">(</span>\n    <span class=\"s2\">&quot;path.to.custom.EmailBackend&quot;</span><span class=\"p\">,</span> option1<span class=\"o\">=</span><span class=\"kc\">True</span><span class=\"p\">,</span> option2<span class=\"o\">=</span><span class=\"s2\">&quot;value&quot;</span>\n<span class=\"p\">)</span>\nmail<span class=\"o\">.</span>send_mail<span class=\"p\">(</span><span class=\"o\">...</span><span class=\"p\">,</span> connection<span class=\"o\">=</span>connection<span class=\"p\">)</span>\nconnection<span class=\"o\">.</span>send_messages<span class=\"p\">([</span>email1<span class=\"p\">,</span> email2<span class=\"p\">])</span>\n</code></pre></div>\n<p>Define a custom <a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> configuration 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>MAILERS <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;default&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span><span class=\"o\">...</span><span class=\"p\">},</span>\n    <span class=\"s2\">&quot;custom&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;BACKEND&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;path.to.custom.EmailBackend&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;OPTIONS&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;option1&quot;</span><span class=\"p\">:</span> <span class=\"kc\">True</span><span class=\"p\">,</span>\n            <span class=\"s2\">&quot;option2&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;value&quot;</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p>And then 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>mail<span class=\"o\">.</span>send_mail<span class=\"p\">(</span><span class=\"o\">...</span><span class=\"p\">,</span> using<span class=\"o\">=</span><span class=\"s2\">&quot;custom&quot;</span><span class=\"p\">)</span>\nmail<span class=\"o\">.</span>mailers<span class=\"p\">[</span><span class=\"s2\">&quot;custom&quot;</span><span class=\"p\">]</span><span class=\"o\">.</span>send_messages<span class=\"p\">([</span>email1<span class=\"p\">,</span> email2<span class=\"p\">])</span>\n</code></pre></div>\n</li>\n</ul>\n</section>\n<section id=\"replacing-fail-silently\">\n<span id=\"migrating-to-mailers-fail-silently\"></span><h2>Replacing <code class=\"docutils literal notranslate\">fail_silently</code><a class=\"heading-anchor\" href=\"#replacing-fail-silently\"><span class=\"visually-hidden\">Lien vers cette rubrique</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>The deprecated <code class=\"docutils literal notranslate\">fail_silently</code> arguments to <a class=\"reference internal\" href=\"/fr/6.1/topics/email/#django.core.mail.send_mail\" title=\"django.core.mail.send_mail\"><code class=\"xref py py-func docutils literal notranslate\">send_mail()</code></a>,\n<a class=\"reference internal\" href=\"/fr/6.1/topics/email/#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>, <a class=\"reference internal\" href=\"/fr/6.1/topics/email/#django.core.mail.mail_admins\" title=\"django.core.mail.mail_admins\"><code class=\"xref py py-func docutils literal notranslate\">mail_admins()</code></a>, <a class=\"reference internal\" href=\"/fr/6.1/topics/email/#django.core.mail.mail_managers\" title=\"django.core.mail.mail_managers\"><code class=\"xref py py-func docutils literal notranslate\">mail_managers()</code></a>, and\n<a class=\"reference internal\" href=\"/fr/6.1/topics/email/#django.core.mail.EmailMessage.send\" title=\"django.core.mail.EmailMessage.send\"><code class=\"xref py py-meth docutils literal notranslate\">EmailMessage.send()</code></a> can be replaced in several ways. Existing usage\nseems to have several different expectations for the behavior, many of which\ndon’t match the actual (and email backend-dependent) implementation. Consider\nremoving <code class=\"docutils literal notranslate\">fail_silently</code> entirely if there is not a specific need for it.</p>\n<p>Calls with <code class=\"docutils literal notranslate\">fail_silently=True</code> should be updated with one of these options,\ndepending on the caller’s intent:</p>\n<ul>\n<li><p>To send a message if email has been configured but avoid raising an error\nif it hasn’t (e.g., in a reusable library), wrap the send call in <code class=\"docutils literal notranslate\">try:</code> /\n<code class=\"docutils literal notranslate\">except mail.MailerDoesNotExist: pass</code>.</p></li>\n<li><p>To ignore <em>all</em> exceptions (e.g., to avoid cascading failures in an error\nhandler that sends mail), wrap the send call in <code class=\"docutils literal notranslate\">try:</code> / <code class=\"docutils literal notranslate\">except\nException: pass</code>.</p></li>\n<li><p>To ignore only SMTP-related errors, wrap the send call in <code class=\"docutils literal notranslate\">try</code> /\n<code class=\"docutils literal notranslate\">except OSError: pass</code>. Note that this ignores both transient network\nglitches <em>and</em> SMTP configuration problems (just like the existing SMTP\nemail backend <code class=\"docutils literal notranslate\">fail_silently</code> implementation).</p></li>\n<li><p>To ignore end user typos in <code class=\"docutils literal notranslate\">to</code> addresses and other delivery problems,\nremove the <code class=\"docutils literal notranslate\">fail_silently</code> argument. Recipient errors are not generally\ndetected at send time, so using <code class=\"docutils literal notranslate\">fail_silently</code> for this purpose doesn’t\naccomplish anything and could mask other problems like configuration errors.</p>\n<p>(In <em>local delivery</em> configurations, SMTP servers may report some recipient\nerrors at send time. If you are using <code class=\"docutils literal notranslate\">fail_silently</code> specifically to\nignore those errors, consider instead intercepting\n<a class=\"reference external\" href=\"https://docs.python.org/3/library/smtplib.html#smtplib.SMTPRecipientsRefused\" title=\"(disponible dans Python v3.14)\"><code class=\"xref py py-exc docutils literal notranslate\">SMTPRecipientsRefused</code></a> and/or\n<a class=\"reference external\" href=\"https://docs.python.org/3/library/smtplib.html#smtplib.SMTPResponseException\" title=\"(disponible dans Python v3.14)\"><code class=\"xref py py-exc docutils literal notranslate\">SMTPResponseException</code></a>s with particular <code class=\"docutils literal notranslate\">smtp_code</code>\nvalues as a more precise filter.)</p>\n</li>\n<li><p>To create an email configuration that ignores certain backend-dependent\nerrors and reuse it for multiple sending operations, create a custom\n<a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> configuration with <code class=\"docutils literal notranslate\">&quot;fail_silently&quot;: True</code> in the\n<a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-MAILERS-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\">&quot;OPTIONS&quot;</code></a>, then refer to that configuration\nwith <code class=\"docutils literal notranslate\">using</code> in the send call.</p></li>\n</ul>\n<p>Calls with <code class=\"docutils literal notranslate\">fail_silently=False</code> should be updated to remove the\n<code class=\"docutils literal notranslate\">fail_silently</code> arg, as that is the default.</p>\n<p>If you use <a class=\"reference internal\" href=\"/fr/6.1/ref/logging/#django.utils.log.AdminEmailHandler\" title=\"django.utils.log.AdminEmailHandler\"><code class=\"xref py py-class docutils literal notranslate\">AdminEmailHandler</code></a> or <a class=\"reference internal\" href=\"/fr/6.1/ref/middleware/#django.middleware.common.BrokenLinkEmailsMiddleware\" title=\"django.middleware.common.BrokenLinkEmailsMiddleware\"><code class=\"xref py py-class docutils literal notranslate\">BrokenLinkEmailsMiddleware</code></a>\nand rely on their previous fail-silent behavior, see\n<a class=\"reference internal\" href=\"#migrating-to-mailers-error-reporting\"><span class=\"std std-ref\">Ignoring transient failures in error reporting</span></a>.</p>\n</section>\n<section id=\"migrating-custom-email-backends\">\n<span id=\"migrating-to-mailers-email-backends\"></span><h2>Migrating custom email backends<a class=\"heading-anchor\" href=\"#migrating-custom-email-backends\"><span class=\"visually-hidden\">Lien vers cette rubrique</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Custom <code class=\"docutils literal notranslate\">EmailBackend</code> implementations may need to be updated for\ncompatibility with mailers.</p>\n<ul class=\"simple\">\n<li><p>In the backend’s <code class=\"docutils literal notranslate\">__init__()</code> method, accept explicit keyword arguments for\nall configuration options that can come from <a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-MAILERS-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\">&quot;OPTIONS&quot;</code></a>. Backends that use custom settings for configuration can\ncontinue to do so (or not, as they choose), but keyword arguments should take\nprecedence over settings.</p></li>\n<li><p>Accept variable <code class=\"docutils literal notranslate\">**kwargs</code> and pass them to superclass init. (This will\ninclude a new <code class=\"docutils literal notranslate\">alias</code> argument which must be passed to the superclass.)\nEnsure that any <code class=\"docutils literal notranslate\">**kwargs</code> used by the backend are <em>not</em> passed to\nsuperclass init, as that would generate an <code class=\"docutils literal notranslate\">InvalidMailer</code> error for\nunknown OPTIONS.</p></li>\n<li><p>Backends must now handle <code class=\"docutils literal notranslate\">fail_silently</code> themselves, if they want to\nsupport it. There is no requirement to support <code class=\"docutils literal notranslate\">fail_silently</code>, and\nbackends that don’t offer it should eliminate that keyword argument. (Do not\npass an explicit <code class=\"docutils literal notranslate\">fail_silently</code> arg to superclass init.)</p></li>\n<li><p>Do not accept variable positional <code class=\"docutils literal notranslate\">*args</code> or pass them to superclass init.</p></li>\n</ul>\n<p>The <code class=\"docutils literal notranslate\">BaseEmailBackend</code> superclass now initializes an <code class=\"docutils literal notranslate\">alias</code> attribute.\nThis is useful for error messages (e.g., <code class=\"docutils literal notranslate\">raise InvalidMailer(f&quot;Bad host\n{host}&quot;, alias=self.alias)</code>), but should not be used for accessing\n<code class=\"docutils literal notranslate\">settings.MAILERS</code> directly. All OPTIONS for a mailer configuration are\npassed to backend init as keyword arguments.</p>\n<p>For reusable libraries that want to support compatibility with deprecated mail\nfunctions and settings, or that support older Django versions:</p>\n<ul class=\"simple\">\n<li><p>A backend can detect it is being initialized without <a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> by\nchecking if <code class=\"docutils literal notranslate\">self.alias is None</code>. (Django’s built-in backends check this to\ndecide whether deprecated settings should be used.) Libraries supporting\nolder Django versions will need to use <code class=\"docutils literal notranslate\">getattr(self, &quot;alias&quot;, None)</code>.</p></li>\n<li><p>Backends that borrow Django’s SMTP email settings like <a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-EMAIL_HOST\"><code class=\"xref std std-setting docutils literal notranslate\">EMAIL_HOST</code></a>\nmust <em>not</em> try to access them when <a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> is in use (<code class=\"docutils literal notranslate\">self.alias\nis not None</code>), as this will cause a « not available when MAILERS is defined »\n<code class=\"docutils literal notranslate\">AttributeError</code>.</p></li>\n<li><p>Libraries supporting multiple Django versions can identify support for\nmailers with either <code class=\"docutils literal notranslate\">hasattr(django.core.mail, &quot;mailers&quot;)</code> or\n<code class=\"docutils literal notranslate\">django.VERSION &gt;= (6, 1)</code>.</p></li>\n</ul>\n</section>\n<section id=\"replacing-auth-user-and-auth-password\">\n<span id=\"migrating-to-mailers-auth\"></span><h2>Replacing <code class=\"docutils literal notranslate\">auth_user</code> and <code class=\"docutils literal notranslate\">auth_password</code><a class=\"heading-anchor\" href=\"#replacing-auth-user-and-auth-password\"><span class=\"visually-hidden\">Lien vers cette rubrique</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>The deprecated <code class=\"docutils literal notranslate\">auth_user</code> and <code class=\"docutils literal notranslate\">auth_password</code> arguments to\n<a class=\"reference internal\" href=\"/fr/6.1/topics/email/#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=\"/fr/6.1/topics/email/#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> can be replaced by defining a\ncustom <a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> configuration with\n<code class=\"docutils literal notranslate\">&quot;username&quot;</code> and <code class=\"docutils literal notranslate\">&quot;password&quot;</code> <a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-MAILERS-OPTIONS\"><code class=\"xref std std-setting docutils literal notranslate\">&quot;OPTIONS&quot;</code></a>, and\nrefer to that configuration with the <code class=\"docutils literal notranslate\">using</code> argument when sending mail.</p>\n<p>For example, to upgrade:</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>mail<span class=\"o\">.</span>send_mail<span class=\"p\">(</span><span class=\"o\">...</span><span class=\"p\">,</span> auth_user<span class=\"o\">=</span><span class=\"s2\">&quot;admin&quot;</span><span class=\"p\">,</span> auth_password<span class=\"o\">=</span><span class=\"s2\">&quot;admin-password&quot;</span><span class=\"p\">)</span>\n</code></pre></div>\n<p>Add a custom <a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> configuration 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>MAILERS <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"c1\"># Existing default configuration.</span>\n    <span class=\"s2\">&quot;default&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;OPTIONS&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;host&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;smtp.example.com&quot;</span><span class=\"p\">,</span>\n            <span class=\"s2\">&quot;username&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;default-user&quot;</span><span class=\"p\">,</span>\n            <span class=\"s2\">&quot;password&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;default-password&quot;</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n    <span class=\"c1\"># Duplicate the default configuration, changing the auth.</span>\n    <span class=\"s2\">&quot;admin-config&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;OPTIONS&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;host&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;smtp.example.com&quot;</span><span class=\"p\">,</span>\n            <span class=\"s2\">&quot;username&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;admin&quot;</span><span class=\"p\">,</span>\n            <span class=\"s2\">&quot;password&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;admin-password&quot;</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p>And then refer to it when sending:</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>mail<span class=\"o\">.</span>send_mail<span class=\"p\">(</span><span class=\"o\">...</span><span class=\"p\">,</span> using<span class=\"o\">=</span><span class=\"s2\">&quot;admin-config&quot;</span><span class=\"p\">)</span>\n</code></pre></div>\n</section>\n<section id=\"updating-adminemailhandler-email-backend\">\n<span id=\"migrating-to-mailers-adminemailhandler\"></span><h2>Updating AdminEmailHandler <code class=\"docutils literal notranslate\">email_backend</code><a class=\"heading-anchor\" href=\"#updating-adminemailhandler-email-backend\"><span class=\"visually-hidden\">Lien vers cette rubrique</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>The deprecated <code class=\"docutils literal notranslate\">email_backend</code> argument to the logging\n<a class=\"reference internal\" href=\"/fr/6.1/ref/logging/#django.utils.log.AdminEmailHandler\" title=\"django.utils.log.AdminEmailHandler\"><code class=\"xref py py-class docutils literal notranslate\">AdminEmailHandler</code></a> can be replaced with a custom\n<a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> configuration, referring to it with the <code class=\"docutils literal notranslate\">using</code>\nargument.</p>\n<p>For example, if your settings include:</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>LOGGING <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"c1\"># ...</span>\n    <span class=\"s2\">&quot;handlers&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;mail_admins&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;class&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.utils.log.AdminEmailHandler&quot;</span><span class=\"p\">,</span>\n            <span class=\"s2\">&quot;email_backend&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;third.party.EmailBackend&quot;</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n    <span class=\"c1\"># ...</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p>Replace that with:</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>LOGGING <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"c1\"># ...</span>\n    <span class=\"s2\">&quot;handlers&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;mail_admins&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"s2\">&quot;class&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.utils.log.AdminEmailHandler&quot;</span><span class=\"p\">,</span>\n            <span class=\"s2\">&quot;using&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;admin-logging&quot;</span><span class=\"p\">,</span>  <span class=\"c1\"># defined in MAILERS</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n    <span class=\"c1\"># ...</span>\n<span class=\"p\">}</span>\n\nMAILERS <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;default&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span><span class=\"o\">...</span><span class=\"p\">},</span>\n    <span class=\"s2\">&quot;admin-logging&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;BACKEND&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;third.party.EmailBackend&quot;</span><span class=\"p\">,</span>\n    <span class=\"p\">},</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n</section>\n<section id=\"ignoring-transient-failures-in-error-reporting\">\n<span id=\"migrating-to-mailers-error-reporting\"></span><h2>Ignoring transient failures in error reporting<a class=\"heading-anchor\" href=\"#ignoring-transient-failures-in-error-reporting\"><span class=\"visually-hidden\">Lien vers cette rubrique</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Django includes two features that report errors via email:\n<a class=\"reference internal\" href=\"/fr/6.1/ref/logging/#django.utils.log.AdminEmailHandler\" title=\"django.utils.log.AdminEmailHandler\"><code class=\"xref py py-class docutils literal notranslate\">AdminEmailHandler</code></a> and <a class=\"reference internal\" href=\"/fr/6.1/ref/middleware/#django.middleware.common.BrokenLinkEmailsMiddleware\" title=\"django.middleware.common.BrokenLinkEmailsMiddleware\"><code class=\"xref py py-class docutils literal notranslate\">BrokenLinkEmailsMiddleware</code></a>. In\nearlier releases, those features used the deprecated <a class=\"reference internal\" href=\"#migrating-to-mailers-fail-silently\"><span class=\"std std-ref\">fail_silently</span></a> argument. Starting in Django 2028 – or\nimmediately once the <a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a> setting is defined – those features no\nlonger use <code class=\"docutils literal notranslate\">fail_silently</code> so no longer ignore certain backend-specific\nerrors.</p>\n<p>This may affect projects that use those features with an unreliable SMTP\nconnection and rely on silently ignoring temporary network failures (and\ncertain SMTP configuration errors). If you want to continue dropping error\nnotification emails that cannot be sent, define a <a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-MAILERS\"><code class=\"xref std std-setting docutils literal notranslate\">MAILERS</code></a>\nconfiguration with the <code class=\"docutils literal notranslate\">&quot;fail_silently&quot;</code> option enabled for use by those\nerror handlers:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>MAILERS <span class=\"o\">=</span> <span class=\"p\">{</span>\n    <span class=\"s2\">&quot;default&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span><span class=\"o\">...</span><span class=\"p\">},</span>\n    <span class=\"s2\">&quot;admin-logging&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n        <span class=\"s2\">&quot;BACKEND&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;django.core.mail.backends.smtp.EmailBackend&quot;</span><span class=\"p\">,</span>\n        <span class=\"s2\">&quot;OPTIONS&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n            <span class=\"c1\"># ... other SMTP options ...</span>\n            <span class=\"s2\">&quot;fail_silently&quot;</span><span class=\"p\">:</span> <span class=\"kc\">True</span><span class=\"p\">,</span>\n        <span class=\"p\">},</span>\n    <span class=\"p\">},</span>\n<span class=\"p\">}</span>\n</code></pre></div>\n<p>To use this for <a class=\"reference internal\" href=\"/fr/6.1/ref/logging/#django.utils.log.AdminEmailHandler\" title=\"django.utils.log.AdminEmailHandler\"><code class=\"xref py py-class docutils literal notranslate\">AdminEmailHandler</code></a>, set the <code class=\"docutils literal notranslate\">&quot;using&quot;</code> option in the\n<a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-LOGGING\"><code class=\"xref std std-setting docutils literal notranslate\">LOGGING</code></a> config as shown in the previous section.</p>\n<p>To use this for <a class=\"reference internal\" href=\"/fr/6.1/ref/middleware/#django.middleware.common.BrokenLinkEmailsMiddleware\" title=\"django.middleware.common.BrokenLinkEmailsMiddleware\"><code class=\"xref py py-class docutils literal notranslate\">BrokenLinkEmailsMiddleware</code></a>, create a subclass that\ndefines <code class=\"docutils literal notranslate\">using</code>, and then specify the path to that subclass in your\n<a class=\"reference internal\" href=\"/fr/6.1/ref/settings/#std-setting-MIDDLEWARE\"><code class=\"xref std std-setting docutils literal notranslate\">MIDDLEWARE</code></a> setting:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.middleware.common</span> <span class=\"kn\">import</span> BrokenLinkEmailsMiddleware\n\n\n<span class=\"k\">class</span> <span class=\"nc\">CustomBrokenLinkEmailsMiddleware</span><span class=\"p\">(</span>BrokenLinkEmailsMiddleware<span class=\"p\">):</span>\n    using <span class=\"o\">=</span> <span class=\"s2\">&quot;admin-logging&quot;</span>\n</code></pre></div>\n</section>","rootId":"migrating-email-to-mailers","toc":[{"title":"Migration des réglages","anchor":"migrating-settings","children":[]},{"title":"Reusable library readiness","anchor":"reusable-library-readiness","children":[{"title":"Solving « not available when MAILERS is defined » errors","anchor":"solving-not-available-when-mailers-is-defined-errors","children":[]}]},{"title":"Replacing get_connection() and connection arguments","anchor":"replacing-get-connection-and-connection-arguments","children":[]},{"title":"Replacing fail_silently","anchor":"replacing-fail-silently","children":[]},{"title":"Migrating custom email backends","anchor":"migrating-custom-email-backends","children":[]},{"title":"Replacing auth_user and auth_password","anchor":"replacing-auth-user-and-auth-password","children":[]},{"title":"Updating AdminEmailHandler email_backend","anchor":"updating-adminemailhandler-email-backend","children":[]},{"title":"Ignoring transient failures in error reporting","anchor":"ignoring-transient-failures-in-error-reporting","children":[]}],"breadcrumbs":[{"docname":"howto/index","title":"Guides pratiques","url":"/fr/6.1/howto/"}],"prev":{"docname":"howto/custom-shell","title":"Comment personnaliser la commande shell","url":"/fr/6.1/howto/custom-shell/"},"next":{"docname":"faq/index","title":"FAQ Django","url":"/fr/6.1/faq/"},"formats":{"html":"/fr/6.1/howto/mailers-migration/","markdown":"/fr/6.1/howto/mailers-migration.md","json":"/fr/6.1/howto/mailers-migration.json"},"source":"https://github.com/django/django/blob/stable/6.1.x/docs/howto/mailers-migration.txt","official":"https://docs.djangoproject.com/fr/6.1/howto/mailers-migration/","inVersions":["6.1"],"inLocales":["en","sv","zh-hans","ga","fr","ja","id","it","pt-br","ko","es","el","pl"]}