0

I'm trying to send an "email" from a website in django. I have completed the main code for doing so:

-)the view function -)the URLs mapping to make the function reachable from code -)the sending form at a template

So my sending form would trigger the view function using the path specified in the URLS.

On my server, I have a "postfix" instance installed and tried.

I tried to edit changes in the settings.py and the views.py for about 2 days now but nothing worked.

The errors range between these two

1)

SMTPNotSupportedError at /website/email_send

when settings are

EMAIL_HOST = 'mydomain.com'
EMAIL_PORT = 25 //same for port 587
EMAIL_HOST_USER = 'uname'
EMAIL_HOST_PASSWORD = 'pwd!'
EMAIL_USE_TLS = True

2)

gaierror at /website/email_send
[Errno -2] Name or service not known

when settings are

EMAIL_HOST = 'mail.mydomain.com' or 'smtp.mydomain.com'

EMAIL_PORT = 25 //same for port 587
EMAIL_HOST_USER = 'uname'
EMAIL_HOST_PASSWORD = 'pwd!'
EMAIL_USE_TLS = True

I expect the email to be sent using a form in my django site run on a server using postfix

Mohammed Baashar
  • 484
  • 3
  • 6
  • 20
  • 1
    If postfix is running on the same machine, try supplying `localhost` or `127.0.0.1` to `EMAIL_HOST`. If it is on another machine, then you'd need to set appropriate MX records in your DNS settings. – xyres Jun 23 '19 at 14:07
  • I changed it to "localhost" and the error message changed to ConnectionRefusedError at /website/email_send [Errno 111] Connection refused – Mohammed Baashar Jun 23 '19 at 14:11
  • problem is not on your code, it is the server. – Ken Jun 23 '19 at 14:12
  • @MohammedBaashar Is postfix running? If yes, is it running on port 25? – xyres Jun 23 '19 at 14:14
  • @xyres I kept it on the default since installation (that is port 25). Yes it is running and receiving mail – Mohammed Baashar Jun 23 '19 at 14:20
  • @Ken thought so. I revised the code million times – Mohammed Baashar Jun 23 '19 at 14:22
  • @MohammedBaashar Seems like postfix is not configured to accept connections from localhost. See if you can connect with it using the `telnet` command: `telnet localhost 25`. – xyres Jun 23 '19 at 14:27

1 Answers1

0

The problem is now fixed. I found this question and used its answer:

Postfix + Django: SMTPException: SMTP AUTH extension not supported by server

I removed EMAIL_HOST_USER = 'uname' and EMAIL_HOST_PASSWORD = 'pwd!'

Then it worked without errors. The settings now are: ... EMAIL_HOST = 'localhost' EMAIL_PORT = 25 EMAIL_USE_TLS = True ...

Mohammed Baashar
  • 484
  • 3
  • 6
  • 20