title: How to test localhost connection to smtp.office365.com or smtp.gmail.com using TLS on port 587
body: <p>I am working locally on OS X using a website (PHP) to send an email using smtp.office365.com or smtp.gmail.com / port 587 (TLS). I have the right username and password so it's not that!</p>
  
  <p>I get a connection error and don't know how to figure out if I need a port opened or if the issue lies somewhere else.</p>
  
  <p>Using Network Utility I can see that port 587 is not open:</p>
  
  <p><a href="https://i.stack.imgur.com/XtGlm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XtGlm.png" alt="enter image description here"></a></p>
  
  <p>Would I need to open a port for localhost and also my router? I want to know that the port blocking is not the issue.</p>
  
  <p>When I run the following command:</p>
  
  <pre><code>nmap -p 587 localhost
  </code></pre>
  
  <p>I get the response:</p>
  
  <pre><code>Nmap scan report for localhost (127.0.0.1)
  Host is up (0.00017s latency).
  Other addresses for localhost (not scanned): ::1 fe80::1
  PORT    STATE  SERVICE
  587/tcp closed submission
  </code></pre>
  
  <p>Here is the log I am getting from ezPublish:</p>
  
  <pre><code>[ Feb 29 2016 20:52:53 ] Unexpected error, the message was : An error occured     
  while sending or receiving mail. Failed to connect to the smtp server: smtp.gmail.com:587. 
  in /Library/WebServer/Documents/test.com/lib/ezc/Mail/src/transports/smtp/smtp_transport.php
  on line 512
  </code></pre>
  
  <p>I get the same error when i use smtp.office365.com as well.</p>