Skip to content

Instantly share code, notes, and snippets.

@andreagrandi
Last active November 25, 2023 14:36
Show Gist options
  • Save andreagrandi/7027319 to your computer and use it in GitHub Desktop.
Save andreagrandi/7027319 to your computer and use it in GitHub Desktop.
Sending emails from Django during development without using a real SMTP server. Python comes with a very basic and integrated SMTP server. To start it just open a terminal and type: python -m smtpd -n -c DebuggingServer localhost:1025 Then configure your settings.py using the following parameters. You will see the email directly in the terminal …
if DEBUG:
EMAIL_HOST = 'localhost'
EMAIL_PORT = 1025
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_USE_TLS = False
DEFAULT_FROM_EMAIL = 'testing@example.com'
@Dooweed
Copy link

Dooweed commented Aug 19, 2020

Thank you a lot

@yashdattsawant
Copy link

Thanks That helped me

@Dunedan
Copy link

Dunedan commented Oct 11, 2021

An even easier solution is to set the email backend to the console backend, as this doesn't require running an SMTP server in a separate process and results in email contents getting printed to stdout directly:

if DEBUG:
    EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"

@Vicenciomf1
Copy link

you saved my life, thank you so much

@ccll
Copy link

ccll commented Oct 28, 2022

Another option is to use 'inbucket' which is a fake email SMTP/POP3 server, with a Web UI to preview the emails.
Run it locally with docker-compose is super easy:

services:
  mail:
    image: inbucket/inbucket:stable
    ports:
      - 2500:2500 # SMTP
      - 1100:1100 # POP3
      - 9000:9000 # web interface

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment