Email configuration in Django.
how to configure email using SMTP:
javascriptCopy code
import os from django.core.mail import EmailMessage from django.conf import settings
arduinoCopy code
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
makefileCopy code
EMAIL_HOST = 'smtp.gmail.com' EMAIL_PORT = 587 EMAIL_USE_TLS = True EMAIL_HOST_USER = '[email protected]' EMAIL_HOST_PASSWORD = 'your_email_password'
Note: Replace the email and password fields with your own email and password.
scssCopy code
def send_email(subject, body, recipient_list): email = EmailMessage( subject=subject, body=body, from_email=settings.DEFAULT_FROM_EMAIL, to=recipient_list ) email.send()
Note: Replace the 'DEFAULT_FROM_EMAIL' field in the 'from_email' parameter with your own email address.
arduinoCopy code
send_email('Test Email', 'This is a test email', ['[email protected]', '[email protected]'])
Note: Replace the subject, body, and recipient list fields with your own values.
That's it! You have now configured email in Django and tested the email configuration.