title: Send an email using python script
body: <p>Today I needed to send email from a Python script. As always I searched Google and found the following script that fits to my need.</p>
  
  <pre><code>import smtplib
  
  SERVER = "localhost"
  
  FROM = "sender@example.com"
  TO = ["user@example.com"] # must be a list
  
  SUBJECT = "Hello!"
  
  TEXT = "This message was sent with Python's smtplib."
  
  # Prepare actual message
  
  message = """\
  From: %s
  To: %s
  Subject: %s
  
  %s
  """ % (FROM, ", ".join(TO), SUBJECT, TEXT)
  
  # Send the mail
  
  server = smtplib.SMTP(SERVER)
  server.sendmail(FROM, TO, message)
  server.quit()
  </code></pre>
  
  <p>But when I tried to run the program, I got the following error message:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:/Python26/email.py", line 1, in &lt;module&gt;
      import smtplib
    File "C:\Python26\lib\smtplib.py", line 46, in &lt;module&gt;
      import email.utils
    File "C:/Python26/email.py", line 24, in &lt;module&gt;
      server = smtplib.SMTP(SERVER)
  AttributeError: 'module' object has no attribute 'SMTP'
  </code></pre>
  
  <p>How can i solve this problem? Any one can help me?</p>
  
  <p>Thanks in advance,
  Nimmy.</p>
  
  <hr>
  
  <p>changed the name to emailsendin .py. But I got the following error</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Python26\emailsending.py", line 24, in &lt;module&gt;
      server = smtplib.SMTP(SERVER)
    File "C:\Python26\lib\smtplib.py", line 239, in __init__
      (code, msg) = self.connect(host, port)
    File "C:\Python26\lib\smtplib.py", line 295, in connect
      self.sock = self._get_socket(host, port, self.timeout)
    File "C:\Python26\lib\smtplib.py", line 273, in _get_socket
      return socket.create_connection((port, host), timeout)
    File "C:\Python26\lib\socket.py", line 512, in create_connection
      raise error, msg
  error: [Errno 10061] No connection could be made because the target machine actively refused it
  </code></pre>