0

Below is my code which sends a mail to my users:

mail = EmailMultiAlternatives(subject=subject, body=text_content, from_email="email@host.com", to=["email@host.com"], bcc=["email@host.com"])
mail.attach_file(model.document.path)
mail.attach_alternative(html_content, "text/html")
mail_status = mail.send()

And my settings.py is as below:

EMAIL_HOST = "mail.host.com"
EMAIL_PORT = 587

EMAIL_HOST_USER = "email@host.com"
EMAIL_HOST_PASSWORD = str(os.getenv('EMAIL_HOST_PASSWORD'))

The problem is that the above code works absolutely fine in my local Windows machine but the code hangs and shows no output when running in my remote server running Ubuntu (Linux).

Any idea where I am going wrong?

1 Answers1

0

Most likely this will be a port issue. The best way to confirm this is by using telnet client.

telnet mail.host.com 587

If you are not seeing Connected text after issuing this command, then the problem is most likely because of the port. In that case you might have to explicitly open this port.

Abdul Niyas P M
  • 18,035
  • 2
  • 25
  • 46