title: Best way to send email with Python on Mac or Linux?
body: <p>I want to send emails with my python script, but unfortunately it's not as straightforward and smooth as php, where I can just use mail() function.</p>
  
  <p>I've used this example:</p>
  
  <pre><code>    import smtplib
      FROM = "sender@example.com"
      TO = ["me@gmail.com"]
  
      SUBJECT = "Hello!"
  
      TEXT = "This message was sent with Python's smtplib."
      server = smtplib.SMTP(SERVER)
      server.sendmail(FROM, TO, message)
      server.quit()
  </code></pre>
  
  <p>but it only returns a whole bunch of errors I don't even know the meaning of...</p>
  
  <pre><code>Traceback (most recent call last):
    File "mylo.py", line 70, in &lt;module&gt;
      sys.exit(main())
    File "mylo.py", line 66, in main
      send_mail()
    File "mylo.py", line 37, in send_mail
      server = smtplib.SMTP(SERVER)
    File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/smtplib.py", line 239, in __init__
      (code, msg) = self.connect(host, port)
    File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/smtplib.py", line 295, in connect
      self.sock = self._get_socket(host, port, self.timeout)
    File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/smtplib.py", line 273, in _get_socket
      return socket.create_connection((port, host), timeout)
    File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/socket.py", line 512, in create_connection
      raise error, msg
  socket.error: [Errno 61] Connection refused
  </code></pre>
  
  <p><strong>How do I send emails with python?</strong> </p>