# Email problem

**URL:** <https://forum.djangoproject.com/t/email-problem/34144>\
**Category:** Mystery Errors\
**Created:** [August 24, 2024, 6:32pm UTC](https://forum.djangoproject.com/t/email-problem/34144 "2024-08-24T18:32:13Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hizar62](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/hizar62/32/23435_2.png) [@Hizar62](https://forum.djangoproject.com/u/Hizar62)\
**Post date:** [August 24, 2024, 6:32pm UTC](https://forum.djangoproject.com/t/email-problem/34144/1 "2024-08-24T18:32:13Z")

</div>

I want to send an email using a Django app, but the email isn’t being sent. I’ve tried Mailtrap, SendGrid, Mailgun, and Google Gmail. Everything seems to be configured correctly in the settings.py file, but the email still isn’t being sent. The console shows that the email was sent, but in reality, no email is being received. Can anyone help me figure out what’s wrong?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 24, 2024, 6:55pm UTC](https://forum.djangoproject.com/t/email-problem/34144/2 "2024-08-24T18:55:47Z")

</div>

Welcome @Hizar62 !

We’re going to need more details here to try and help you.

Have you tried using the [`sendtestemail`](https://docs.djangoproject.com/en/5.1/ref/django-admin/#sendtestemail) command to try sending an email from the command line? (If you haven’t, you should.)

We may also need to see all your email settings (except for your email password) and the view that is supposed to send the emails.

What exactly are you seeing on the console that is making you think that the email was sent? (Please copy/paste your console output here, between lines of three backtick - ` characters. Do not post an image here of your console output.)

---

<div class="post-metadata">

**Author:** ![Hizar62](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/hizar62/32/23435_2.png) [@Hizar62](https://forum.djangoproject.com/u/Hizar62)\
**Post date:** [August 25, 2024, 4:44pm UTC](https://forum.djangoproject.com/t/email-problem/34144/3 "2024-08-25T16:44:43Z")

</div>

EMAIL\_BACKEND = ‘django.core.mail.backends.smtp.EmailBackend’

EMAIL\_HOST = ‘live.smtp.mailtrap’

EMAIL\_HOST\_USER = ‘kjnfjkn’

EMAIL\_HOST\_PASSWORD = ‘jdfjkdnfndkf’

EMAIL\_PORT = 587

EMAIL\_USE\_TLS = True

this is the setting.py code where i configure the smtp.

this is the console output  
[25/Aug/2024 21:41:50] “GET /simple\_mail HTTP/1.1” 301 0  
Content-Type: text/plain; charset=“utf-8”  
MIME-Version: 1.0  
Content-Transfer-Encoding: 7bit  
Subject: Thats your subject  
From: django@mailtrap.club  
To: [recipientmail@gmail.com](mailto:recipientmail@gmail.com)  
Date: Sun, 25 Aug 2024 16:41:50 -0000  
Message-ID: [172460411088.jdnfkfndjknkjf15@DESKTOP-njfdnsfjdf](mailto:172460411088.jdnfkfndjknkjf15@DESKTOP-njfdnsfjdf)

## Thats your message body

[25/Aug/2024 21:41:51] “GET /simple\_mail/ HTTP/1.1” 200 13

basically i write simple function to send email

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 25, 2024, 4:59pm UTC](https://forum.djangoproject.com/t/email-problem/34144/4 "2024-08-25T16:59:20Z")

</div>

> [@KenWhitesell](#):
>
> We may also need to see … and the view that is supposed to send the emails.

What you’ve shown here isn’t the view to send the email, nor does it provide any evidence that an email was sent.

You also haven’t shown an attempt to use the `sendtestemail` to demonstrate that your configuration is correct.

---

<div class="post-metadata">

**Author:** ![Hizar62](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/hizar62/32/23435_2.png) [@Hizar62](https://forum.djangoproject.com/u/Hizar62)\
**Post date:** [August 27, 2024, 8:35am UTC](https://forum.djangoproject.com/t/email-problem/34144/5 "2024-08-27T08:35:12Z")

</div>

> [@KenWhitesell](#):
>
> `sendtestemail`

can you give me the simple code for sendtestemail im new in django

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 27, 2024, 11:41am UTC](https://forum.djangoproject.com/t/email-problem/34144/6 "2024-08-27T11:41:01Z")

</div>

It’s a `manage.py` command. You run it from the command line. See the docs for it referenced above.

---

<div class="post-metadata">

**Author:** ![Hizar62](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/hizar62/32/23435_2.png) [@Hizar62](https://forum.djangoproject.com/u/Hizar62)\
**Post date:** [August 29, 2024, 6:23pm UTC](https://forum.djangoproject.com/t/email-problem/34144/7 "2024-08-29T18:23:37Z")

</div>

so i do sendtestmail this is what i got

(env) D:\SideProjects\danube\>python manage.py sendtestemail [boy552@gmail.com](mailto:boy552@gmail.com)  
Content-Type: text/plain; charset=“utf-8”  
MIME-Version: 1.0  
Content-Transfer-Encoding: 7bit  
Subject: Test email from DESKTOP-XXXXXX on 2024-08-29 18:21:23.695804+00:00  
From: webmaster@localhost  
To: [boy552@gmail.com](mailto:boy552@gmail.com)  
Date: Thu, 29 Aug 2024 18:21:23 -0000

## If you’re reading this, it was successful.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 29, 2024, 6:24pm UTC](https://forum.djangoproject.com/t/email-problem/34144/8 "2024-08-29T18:24:45Z")

</div>

And did “[boy552@gmail.com](mailto:boy552@gmail.com)” receive the email?

---

<div class="post-metadata">

**Author:** ![Hizar62](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/hizar62/32/23435_2.png) [@Hizar62](https://forum.djangoproject.com/u/Hizar62)\
**Post date:** [August 29, 2024, 6:27pm UTC](https://forum.djangoproject.com/t/email-problem/34144/9 "2024-08-29T18:27:20Z")

</div>

no, not even in the spam folder

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 29, 2024, 6:31pm UTC](https://forum.djangoproject.com/t/email-problem/34144/10 "2024-08-29T18:31:30Z")

</div>

You should not see the email on the console when you use the sendtestemail command.

You’ve got _something_ wrong with your configuration. Do you possibly have duplicate entries in your settings.py file for these EMAIL settings? Are you sure you’re using the right settings.py file?

That’s the right contents of the email, but it’s directing the email to the console and not the mail server.

---

<div class="post-metadata">

**Author:** ![Hizar62](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/hizar62/32/23435_2.png) [@Hizar62](https://forum.djangoproject.com/u/Hizar62)\
**Post date:** [August 29, 2024, 6:52pm UTC](https://forum.djangoproject.com/t/email-problem/34144/11 "2024-08-29T18:52:08Z")

</div>

i think i follow the offical documentation for the email configuration in settings.py  
and there is no duplication entries i dont know why it is showing on console. and what do you mean by mail server?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 29, 2024, 6:55pm UTC](https://forum.djangoproject.com/t/email-problem/34144/12 "2024-08-29T18:55:50Z")

</div>

> [@Hizar62](#):
>
> i think i follow the offical documentation for the email configuration in settings.py

The only way we can help verify that is if you were to:

- post the complete contents of your settings.pty,
- post the contents of the `manage.py` command you are using,
- and verifying that you do not have the `DJANGO_SETTINGS_MODULE` set as an environment variable.

> [@Hizar62](#):
>
> and what do you mean by mail server?

> [@Hizar62](#):
>
> EMAIL\_HOST = ‘live.smtp.mailtrap’

---

<div class="post-metadata">

**Author:** ![Hizar62](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/hizar62/32/23435_2.png) [@Hizar62](https://forum.djangoproject.com/u/Hizar62)\
**Post date:** [August 29, 2024, 7:14pm UTC](https://forum.djangoproject.com/t/email-problem/34144/13 "2024-08-29T19:14:29Z")

</div>

settings.py

```auto
"""
Django settings for danube project.

Generated by 'django-admin startproject' using Django 4.0.3.

For more information on this file, see
https://docs.djangoproject.com/en/4.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.0/ref/settings/
"""

from pathlib import Path
import os

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path( __file__ ).resolve().parent.parent

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-jdnfkjasnknsfjknsfjkgnfjgnas

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'live.smtp.mailtrap.io'
EMAIL_HOST_USER = 'api'
EMAIL_HOST_PASSWORD = 'nskjnjnsfkjvnjfvknfvnkfnvjnfkvnfjkvnkjf'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'webmaster@localhost' 

import logging
logging.basicConfig(level=logging.DEBUG)

ALLOWED_HOSTS = []

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.humanize',
    'widget_tweaks',
    'account',
    'home',
    'anymail'
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'danube.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'account.context_processors.user_profile'
            ],
        },
    },
]

WSGI_APPLICATION = 'danube.wsgi.application'

# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

MESSAGE_STORAGE = 'django.contrib.messages.storage.cookie.CookieStorage'

# Internationalization
# https://docs.djangoproject.com/en/4.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/

STATIC_URL = '/static/'
MEDIA_URL = '/media/'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'danube/static'),
)
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

```

manage.py

```auto
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys

def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'danube.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)

if __name__ == ' __main__':
    main()

```

i think yes i didnt set DJANGO\_SETTINGS\_MODULE as an env varaible

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 29, 2024, 7:22pm UTC](https://forum.djangoproject.com/t/email-problem/34144/14 "2024-08-29T19:22:57Z")

</div>

> [@Hizar62](#):
>
> and there is no duplication entries

Yes there are. Examine your settings file more carefully.

---

<div class="post-metadata">

**Author:** ![Hizar62](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/hizar62/32/23435_2.png) [@Hizar62](https://forum.djangoproject.com/u/Hizar62)\
**Post date:** [August 29, 2024, 7:25pm UTC](https://forum.djangoproject.com/t/email-problem/34144/15 "2024-08-29T19:25:25Z")

</div>

can you help me? to understand where i make a mistake

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 29, 2024, 7:26pm UTC](https://forum.djangoproject.com/t/email-problem/34144/16 "2024-08-29T19:26:52Z")

</div>

You have the same email-related setting in two different places in your settings.py file. You need to find the duplicate and remove it.

---

<div class="post-metadata">

**Author:** ![Hizar62](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/hizar62/32/23435_2.png) [@Hizar62](https://forum.djangoproject.com/u/Hizar62)\
**Post date:** [August 29, 2024, 7:43pm UTC](https://forum.djangoproject.com/t/email-problem/34144/17 "2024-08-29T19:43:08Z")

</div>

thank you, it is working now!!!
