Error when trying to send email in contact form

Posted June 28, 2020 1.1k views

I have a Mezzanine project hosted in a droplet using as the host. I have a contact form that should send me an email when someone wants to inquire about more information. I get a 500 status code from Nginx when trying to send an email.

Here is when the problem occurs. To produce the problem, I go into my admin page in my Mezzanine project. I go to my Pages, and then select my form page called Contact. Inside this contact form page, I have a few options in the email section. In the from address: I put in a valid email. In the send mail to others: part, I put the same email. That way I am notified when someone sends an inquiry. This is how the problem is produced.

When I leave the send mail to others: part empty, the page works correctly. Although, I don’t get a notification. Here are things I’ve tried:

I have run the python shell command to attempt sending mail that way, and it does successfully. I have also sent emails correctly when just running on my local machine.

I am assuming there is an issue with my droplets server not allowing outgoing emails? I have run the command: sudo ufw allow 587 and it still doesn’t allow me to send emails. Does anyone know what else I can do to further troubleshoot this issue?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hi there @Chair,

I would recommend first checking your Nginx error log to see the actual error rather than the generic 500 error. To do that, you can first trigger the 500 error and then run the following command:

  • sudo tail -100 /var/log/nginx/error.log

This should give you more information on what the actual problem is. Feel free to share the output here as well.

Another thing that I could suggest is to check if the outgoing TCP connections on port 587 are allowed:

  • telnet 587

Let me know how it goes!

  • Hello Bobby,

    Thanks for replying! I have tried triggering the 500 error and then running the tail command, but I got no output. The error log seems to be empty. So, I assume nothing was wrong?

    When running the telnet command, I get this output:

    $ telnet 587
    Connected to
    Escape character is '^]'.

    I also tried

    $ nc -v 587
    Connection to 587 port [tcp/submission] succeeded!

    I don’t know how to troubleshoot this. I checked the Django documentation and this is stated:

    When DEBUG is False, Django will email the users listed in the ADMINS setting whenever your code raises an unhandled exception and results in an internal server error (strictly speaking, for any response with an HTTP status code of 500 or greater). This gives the administrators immediate notification of any errors. The ADMINS will get a description of the error, a complete Python traceback, and details about the HTTP request that caused the error.

    I get no emails either when a status code of 500 or greater is returned. I have my email set, and all my variables are set for EMAIL_HOST.

    • Hi there @Chair,

      What is the SMTP port that you use for If you are using port 25 I would recommend changing it with port 587.

      Regarding the Django DEBUG, I would recommend setting it to true rather than false and see if you get more information rather than the generic 500 error.

      Let me know how it goes.