Send Email Issue - Google Compute Engine VM
<p>I am trying to send an Email from python code. The Code works fine when tested on my local Server. But when I deploy these changes on my Google Compute Engine VM, the Email sending stops and Connection Error starts coming.</p>

<p>Error Trace:</p>

<pre><code>File "/usr/local/lib/python2.7/dist-packages/django/core/mail/message.py", line 342, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/usr/local/lib/python2.7/dist-packages/django/core/mail/backends/smtp.py", line 100, in send_messages
    new_conn_created = self.open()
  File "/usr/local/lib/python2.7/dist-packages/django/core/mail/backends/smtp.py", line 58, in open
    self.connection = connection_class(self.host, self.port, **connection_params)
  File "/usr/lib/python2.7/smtplib.py", line 256, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/lib/python2.7/smtplib.py", line 316, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/lib/python2.7/smtplib.py", line 291, in _get_socket
    return socket.create_connection((host, port), timeout)
  File "/usr/lib/python2.7/socket.py", line 571, in create_connection
    raise err
error: [Errno 110] Connection timed out
</code></pre>

<p>Code: </p>

<pre><code>from django.core.mail import EmailMessage

msg = EmailMessage("Test Sub", "Msg", "abc@abc.in", ["def@abc.in"])
msg.content_subtype = "html"
msg.send()
</code></pre>

<p>Email settings in settings.py File:</p>

<pre><code>EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.zoho.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'abc@abc.in'
EMAIL_HOST_PASSWORD = 'abcxxxabc'
DEFAULT_FROM_EMAIL = 'abc@abc.in'
DEFAULT_TO_EMAIL = 'def@abc.in'
</code></pre>

<p>Can someone please suggest what could be the cause for this behavior ? And how can this issue be resolved ?</p>

<p>Thanks,</p>

<p>You can't send mail directly from google cloud, port 587 is blocked. You're gonna have to find another solution; take a look at Mailgun.</p>

python django google-compute-engine