title: How Do I Send Emails Using Python 3.4 With GMail?
body: <p>I've been trying bits of code such as:</p>
  
  <pre><code>import smtplib
  
  def sendemail(from_addr, to_addr_list, cc_addr_list,
                subject, message,
                login, password,
                smtpserver='smtp.gmail.com:587'):
      header  = 'From: %s\n' % from_addr
      header += 'To: %s\n' % ','.join(to_addr_list)
      header += 'Cc: %s\n' % ','.join(cc_addr_list)
      header += 'Subject: %s\n\n' % subject
      message = header + message
  
      server = smtplib.SMTP(smtpserver)
      server.starttls()
      server.login(login,password)
      problems = server.sendmail(from_addr, to_addr_list, message)
      server.quit()
  
  sendemail(from_addr    = 'python@RC.net', 
          to_addr_list = ['example@gmail.com'],
          cc_addr_list = ['example@gmail.com'], 
          subject      = 'Howdy', 
          message      = 'Hello!', 
          login        = 'example@gmail.com', 
          password     = 'XXXX')
  </code></pre>
  
  <p>Except with an actual password and details.</p>
  
  <p>It brings this error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "User/Python/Email.py", line 27, in &lt;module&gt;
      password     = 'lollol69')
    File "User/Python/Email.py", line 15, in sendemail
      server = smtplib.SMTP(smtpserver)
    File "C:\Python34\lib\smtplib.py", line 242, in __init__
      (code, msg) = self.connect(host, port)
    File "C:\Python34\lib\smtplib.py", line 321, in connect
      self.sock = self._get_socket(host, port, self.timeout)
    File "C:\Python34\lib\smtplib.py", line 292, in _get_socket
      self.source_address)
    File "C:\Python34\lib\socket.py", line 509, in create_connection
      raise err
    File "C:\Python34\lib\socket.py", line 500, in create_connection
      sock.connect(sa)
  TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
  </code></pre>
  
  <p>Ideally, I could know what's wrong with the code and how I can fix this. If it's totally wrong then some working code with Gmail would be greatly appreciated.</p>
  
  <p>Thanks!</p>