
Django Email
Email backend, send_mail, EmailMessage, HTML emails, attachments, async email, Celery integration
1Which Django setting configures the email sending backend?
Which Django setting configures the email sending backend?
回答
The EMAIL_BACKEND setting configures the email sending backend in Django. By default, it uses smtp.EmailBackend which sends emails via SMTP. In development, it's common to use console.EmailBackend to display emails in the console or filebased.EmailBackend to save them to files.
2Which Django function allows sending a simple email with a subject, message, and recipient list?
Which Django function allows sending a simple email with a subject, message, and recipient list?
回答
The send_mail function from django.core.mail is the simplest method to send an email in Django. It takes as required parameters the subject, message, sender, and recipient list. It returns the number of successfully sent emails (0 or 1).
3Which email backend to use in development to display emails in the console instead of sending them?
Which email backend to use in development to display emails in the console instead of sending them?
回答
The django.core.mail.backends.console.EmailBackend backend displays emails in standard output (console) instead of actually sending them. This is ideal for development as it allows checking email content without SMTP configuration and without risking sending test emails to real recipients.
Which Django class to use for creating an email with more control than send_mail, including adding custom headers?
How to send an HTML email with a text fallback version in Django?
+15 面接問題