Prompt

How do I send emails from a Django app?

Technology / Api platforms6 observationsLast seen Oct 7, 2026

Latest observation

Oct 7, 2026GeminiWeb search: on

To send emails from a Django app, configure your email settings in settings.py and use standard Django utilities like send_mail or EmailMultiAlternatives.

Step 1: Configure Email Settings (settings.py)

Option A: Local Development (Console Backend)

For local testing without actually sending emails, Django can print emails directly to your terminal:

Python

# settings.py
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

Option B: Production / SMTP (e.g., Gmail, SendGrid, Mailgun)

For real email delivery using SMTP:

Python

# settings.py
import os

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'  # or your SMTP provider host
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = os.environ.get('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD')  # Use App Password for Gmail
DEFAULT_FROM_EMAIL = 'webmaster@yourdomain.com'

Step 2: Send Emails in Views or Services

Method 1: Send Simple Plain-Text Email

Use send_mail() for basic text notifications:

Python

from django.core.mail import send_mail
from django.http import HttpResponse

def send_simple_email(request):
    send_mail(
        subject='Welcome to Our Site!',
        message='Thank you for signing up for our service.',
        from_email=None,  # Uses DEFAULT_FROM_EMAIL from settings
        recipient_list=['user@example.com'],
        fail_silently=False,
    )
    return HttpResponse("Email sent successfully!")

Method 2: Send HTML Emails with Templates

Render HTML templates alongside a plain-text fallback:

Python

from django.core.mail import EmailMultiAlternatives
from django.template.loader import render_to_string

def send_html_email(user):
    subject = 'Welcome to Our Community'
    from_email = 'no-reply@yourdomain.com'
    to_email = [user.email]

    # Render template contents
    context = {'user_name': user.first_name}
    text_content = f"Hello {user.first_name}, welcome to our platform!"
    html_content = render_to_string('emails/welcome.html', context)

    # Compose multi-part message
    msg = EmailMultiAlternatives(subject, text_content, from_email, to_email)
    msg.attach_alternative(html_content, "text/html")
    msg.send()

Method 3: Send Mass Emails

Use send_mass_mail() to efficiently send multiple distinct messages over a single SMTP connection:

Python

from django.core.mail import send_mass_mail

message1 = ('Subject 1', 'Body 1', 'from@example.com', ['user1@example.com'])
message2 = ('Subject 2', 'Body 2', 'from@example.com', ['user2@example.com'])

send_mass_mail((message1, message2), fail_silently=False)

Best Practices

  • Use Asynchronous Tasks: Sending emails via HTTP requests blocks the request-response cycle. Use task queues like Celery or Huey to deliver emails in the background.
  • Environment Variables: Keep sensitive SMTP credentials out of version control by loading EMAIL_HOST_USER and EMAIL_HOST_PASSWORD via .env files.
  • Transactional Email APIs: For high-volume production setups, third-party APIs (such as Resend, Postmark, or Amazon SES) often offer higher deliverability and lower latency than direct SMTP.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (6 observations for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.