# send eMail from form

**URL:** <https://forum.djangoproject.com/t/send-email-from-form/29151>\
**Category:** Mystery Errors\
**Created:** [March 16, 2024, 11:02am UTC](https://forum.djangoproject.com/t/send-email-from-form/29151 "2024-03-16T11:02:55Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gae58](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/gae58/32/18215_2.png) [@Gae58](https://forum.djangoproject.com/u/Gae58)\
**Post date:** [March 16, 2024, 11:02am UTC](https://forum.djangoproject.com/t/send-email-from-form/29151/1 "2024-03-16T11:02:55Z")

</div>

Hi, I made a web page to allow the user to send a message via eletrronic mail.  
I post the setting of the settings.py file.

```auto
# eMail
DEFAULT_FROM_EMAIL= 'info@personalsoftware.it'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST_USER = config('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD')
# EMAIL_HOST_TLS = config('EMAIL_HOST_TLS')
EMAIL_PORT = config('EMAIL_PORT')
EMAIL_HOST = config('EMAIL_HOST')

```

And the setting of the .env file

```auto
EMAIL_HOST_USER=info@personalsoftware.it
EMAIL_HOST_PASSWORD=XXXXX
EMAIL_USE_TLS=True
EMAIL_PORT=587
EMAIL_HOST=993

```

But it returns this error

```auto
Error sending email: <class 'socket.gaierror'> [Error 11001] getaddrinfo failed
[16/Mar/2024 11:52:36] "POST /email/ HTTP/1.1" 200 54

```

I placed prints in the view file and the error occurs when I launch the send\_mail() function

I don’t know if the settings are correct and I don’t understand where I am wrong  
Thanks

---

<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:** [March 16, 2024, 11:26am UTC](https://forum.djangoproject.com/t/send-email-from-form/29151/2 "2024-03-16T11:26:46Z")

</div>

Side note: When needing to preformat multiple lines, enclose the code between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```. (I’ve taken the liberty of fixing your original post for you.)

> [@Gae58](#):
>
> `EMAIL_HOST=993`

EMAIL\_HOST needs to be the dns name or ip address of the email server, not a port number.

---

<div class="post-metadata">

**Author:** ![Gae58](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/gae58/32/18215_2.png) [@Gae58](https://forum.djangoproject.com/u/Gae58)\
**Post date:** [March 16, 2024, 4:32pm UTC](https://forum.djangoproject.com/t/send-email-from-form/29151/3 "2024-03-16T16:32:40Z")

</div>

I apologize again and thank you for editing it.  
I have made lal modification as you suggested

```auto
EMAIL_HOST_USER=info@yourpersonalsoftware.it
EMAIL_HOST_PASSWORD=XXX
EMAIL_USE_TLS=True
EMAIL_PORT=587
EMAIL_HOST=www.yourpersonalsoftware.it

```

And now this other error comes back. What can I do to make sure it is just a timeout problem and not something else ?  
Below is the error

```auto
Error sending email: <class 'TimeoutError'> [WinError 10060] Unable to establish connection. Incorrect response from the connected party after the time interval or no response from the connected host.
[16/Mar/2024 17:28:03] "POST /email/ HTTP/1.1" 200 54

```

This time I hope I did not make a mistake with the backticks.

---

<div class="post-metadata">

**Author:** ![Gae58](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/gae58/32/18215_2.png) [@Gae58](https://forum.djangoproject.com/u/Gae58)\
**Post date:** [March 16, 2024, 4:43pm UTC](https://forum.djangoproject.com/t/send-email-from-form/29151/4 "2024-03-16T16:43:40Z")

</div>

I removed the www. but same result

---

<div class="post-metadata">

**Author:** ![Gae58](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/gae58/32/18215_2.png) [@Gae58](https://forum.djangoproject.com/u/Gae58)\
**Post date:** [March 16, 2024, 5:05pm UTC](https://forum.djangoproject.com/t/send-email-from-form/29151/5 "2024-03-16T17:05:34Z")

</div>

I’ll post the viewa code. I saw that EmailMessage is used and not send\_mail  
I don’t know if it is the same thing

```auto
def send_email(request):
    try:
        if request.method == 'POST':
            name = request.POST.get('name', '')
            email = request.POST.get('email', '')
            object = request.POST.get('object', '')
            message = request.POST.get('message', '')

            # Send the email
            send_mail(
                subject = subject,
                message = f "From: {name}\nEmail: {email}\nMessage: {message}"
                from_email = email,
                recipient_list = ['info@yourpersonalesoftware.it'],
                fail_silently = False,
            )
            print("Email sent successfully")
            return HttpResponse('workwithus.html')

    except Exception as e:
        print("Error sending email:", type(e), e)
        return HttpResponse('An error occurred while sending the 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:** [March 16, 2024, 7:00pm UTC](https://forum.djangoproject.com/t/send-email-from-form/29151/6 "2024-03-16T19:00:31Z")

</div>

> [@Gae58](#):
>
> `EMAIL_HOST=www.yourpersonalsoftware.it`

Are you running an email server on this system? If not, then this setting is supposed to be the SMTP server that is responsible for sending emails.

---

<div class="post-metadata">

**Author:** ![ahmeddeveloper](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ahmeddeveloper/32/19935_2.png) [@ahmeddeveloper](https://forum.djangoproject.com/u/ahmeddeveloper)\
**Post date:** [March 17, 2024, 6:35am UTC](https://forum.djangoproject.com/t/send-email-from-form/29151/7 "2024-03-17T06:35:06Z")

</div>

use this setting, i did it like this: check email host, and use SSL instead of TLS, and enable ssl/tsl both: I hope it will work for you.

EMAIL\_BACKEND = ‘django.core.mail.backends.smtp.EmailBackend’  
EMAIL\_HOST = ‘[mail.example.com](http://mail.example.com)’ # Outgoing Server  
EMAIL\_PORT = 465 # SMTP Port  
EMAIL\_USE\_SSL = True # Enable SSL/TLS

**#Authentication details**  
EMAIL\_HOST\_USER = ‘donotreply@example.com’ # Your email address  
EMAIL\_HOST\_PASSWORD = ’ ’ # Your email password

**#Additional settings if needed**  
DEFAULT\_FROM\_EMAIL = ‘donotreply@example.com’ # Default sender email address

---

<div class="post-metadata">

**Author:** ![Gae58](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/gae58/32/18215_2.png) [@Gae58](https://forum.djangoproject.com/u/Gae58)\
**Post date:** [March 17, 2024, 10:55am UTC](https://forum.djangoproject.com/t/send-email-from-form/29151/8 "2024-03-17T10:55:43Z")

</div>

Thanks for the suggestions but nothing to do.  
I specify that I am doing the tests on a local production pc. I don’t know if thiso can affect it. Yes from this pc I send e-mails attrvaerso the roundcube webMail  
I also specify that I use the file.env to set the parameters even if it is of little use, since they are definitie in the settings.py file  
I modified the view code making it simple

```auto
        if request.method == 'POST':
            send_mail('Subject to Send MAIL', 'Message to send mail', 'info@yourpersonalesoftware.it', ['gaetano.leoni@gmail.com'])
...

```

But the result doesn’t change  
For completeness I repost the whole code

view

```auto
from django.core.mail import send_mail
from django.conf import settings
def send_email(request):
    try:
        if request.method == 'POST':
            send_mail('Subject to Send MAIL', 'Message to send mail', 'info@yourpersonalesoftware.it', ['gaetano.leoni@gmail.com'])
    except Exception as e:
        print("Error sending email:", type(e), e)
        return HttpResponse('An error occurred while sending the email.')

```

.env

```auto
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST=yourpersonalsoftware.it
EMAIL_PORT = 465 # Porta SMTP
EMAIL_USE_SSL = True # Abilita SSL/TLS

#Dettagli di autenticazione
EMAIL_HOST_USER='info@yourpersonalsoftware.it'
EMAIL_HOST_PASSWORD = 'XXXX' # La tua password email

#Impostazioni aggiuntive se necessarie
#DEFAULT_FROM_EMAIL = 'donotreply@example.com' # Indirizzo email predefinito del mittente

```

.env

```auto
# eMail
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = config('EMAIL_HOST')
EMAIL_PORT = config('EMAIL_PORT')
#EMAIL_HOST_TLS = config('EMAIL_USE_TLS')
EMAIL_HOST_SSL = config('EMAIL_USE_SSL')
#DEFAULT_FROM_EMAIL= 'info@yourpersonalsoftware.it'
EMAIL_HOST_USER = config('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD')

```

Sicuramente sarà un errore stupido ma non lo riesco a capire.

.env

```auto
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST=yourpersonalsoftware.it
EMAIL_PORT = 465 # Porta SMTP
EMAIL_USE_SSL = True # Abilita SSL/TLS

#Dettagli di autenticazione
EMAIL_HOST_USER='info@yourpersonalsoftware.it'
EMAIL_HOST_PASSWORD = 'XXXX' # La tua password email

#Impostazioni aggiuntive se necessarie
#DEFAULT_FROM_EMAIL = 'donotreply@example.com' # Indirizzo email predefinito del mittente

```

.env

```auto
# eMail
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = config('EMAIL_HOST')
EMAIL_PORT = config('EMAIL_PORT')
#EMAIL_HOST_TLS = config('EMAIL_USE_TLS')
EMAIL_HOST_SSL = config('EMAIL_USE_SSL')

Surely it will be a stupid mistake but I can't understand it.
```

---

<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:** [March 17, 2024, 12:16pm UTC](https://forum.djangoproject.com/t/send-email-from-form/29151/9 "2024-03-17T12:16:21Z")

</div>

I’m not asking if you send emails from this system.

Do you have an email **server** installed on `yourpersonalsoftware.it` ? (Roundcube is an email _client_, not an email _server_. Since it is an email _client_, you can check to see what its configuration is to see what email server it connects to.)

If you do not have an email server installed, then this cannot be your EMAIL\_HOST.

What you are looking for is your email server that allows you to make an SMTP connection.
