Skip to content

Commit

Permalink
feat: added SMTP config
Browse files Browse the repository at this point in the history
  • Loading branch information
nimish-ks committed Sep 24, 2023
1 parent 3000c04 commit a6c6835
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
22 changes: 22 additions & 0 deletions backend/backend/api/email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from django.conf import settings
from django.core.mail import send_mail
from django.template.loader import render_to_string

def send_email(subject, recipient_list, template_name, context):
"""
Send email via SMTP gateway through Django's email backend.
"""
# Load the template
email_html_message = render_to_string(template_name, context)

# Get the DEFAULT_FROM_EMAIL from settings
default_from_email = getattr(settings, "DEFAULT_FROM_EMAIL")

# Send the email
send_mail(
subject,
'', # plain text content can be empty as we're sending HTML
default_from_email,
recipient_list,
html_message=email_html_message
)
11 changes: 11 additions & 0 deletions backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,17 @@

OAUTH_REDIRECT_URI = os.getenv('OAUTH_REDIRECT_URI')


# Email configurations
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = os.getenv('SMTP_SERVER')
EMAIL_PORT = int(os.getenv('SMTP_PORT', 587))
EMAIL_USE_TLS = True
EMAIL_HOST_USER = os.getenv('SMTP_USERNAME')
EMAIL_HOST_PASSWORD = os.getenv('SMTP_PASSWORD')
DEFAULT_FROM_EMAIL = os.getenv('DEFAULT_FROM_EMAIL')


SITE_ID = 1

MIDDLEWARE = [
Expand Down

0 comments on commit a6c6835

Please sign in to comment.