definition;
EMAIL_BACKEND is the SMTP backend that Email will be sent through.
EMAIL_HOST is the host to use for sending email.
EMAIL_USE_TLS - Whether to use a TLS (secure) connection when talking to the SMTP server. This is used for explicit TLS connections, generally on port 587.
EMAIL_PORT - Port to use for the SMTP server defined in EMAIL_HOST.
EMAIL_HOST_USER and EMAIL_HOST_PASSWORD are username and password to use for the SMTP server respectively.
add these to views.py;
from django.conf import settings
from django.core.mail import send_mail
To successfully run this, you need to install cripsy forms and add it to installed apps on settings. do that, through the step below;
pip install django-crispy-forms
then;
INSTALLED_APPS = ( ... 'crispy_forms', ).
this method is console base. for filebase, set this up in settings.py
EMAIL_BACKEND = "django.core.mail.backends.filebased.EmailBackend" EMAIL_FILE_PATH = BASE_DIR / "sent_emails"
for smtp server, do the following;
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST = 'smtp.gmail.com' EMAIL_USE_TLS = True EMAIL_PORT = 587 EMAIL_HOST_USER = 'your gmail account' EMAIL_HOST_PASSWORD = 'your account’s password'
definition; EMAIL_BACKEND is the SMTP backend that Email will be sent through. EMAIL_HOST is the host to use for sending email. EMAIL_USE_TLS - Whether to use a TLS (secure) connection when talking to the SMTP server. This is used for explicit TLS connections, generally on port 587. EMAIL_PORT - Port to use for the SMTP server defined in EMAIL_HOST. EMAIL_HOST_USER and EMAIL_HOST_PASSWORD are username and password to use for the SMTP server respectively.
add these to views.py; from django.conf import settings from django.core.mail import send_mail
def mail(request): subject = 'your subject' message = 'your message' email_from = settings.EMAIL_HOST_USER recipient_list = ['receiver's mail address', ] return render(request,'login.html')
add this to the app's url; urlpatterns = [ ........... path('mail', views.mail, name ='mail'), ]