title: Error in sending email from a Amazon Lambda function using python SMTP library
body: <p>I am trying to send an email from an <code>Amazon Lambda function</code> using <code>python's</code> <code>SMTP</code> library. Here is my code so far:</p>
  
  <pre><code>import smtplib
  from_addr = 'fromemailid@company.com'
  username = 'user1'
  password = 'pwd'
  
  def send_email():
  
  
      to_addrs = "user1@company.com"
  
      msg = "\r\n".join([
          "From: fromemailid@company.com",
          "To: "+to_addrs,
          "Subject: Test Email ",
          "",
          "Hello" + ", \n This is a test email"
      ])
  
      server = smtplib.SMTP('123.45.678.9')
      server.ehlo()
      server.starttls()
      server.login(username, password)
      server.sendmail(from_addr, to_addrs, msg)
      server.quit()
  
  if __name__ == '__main__':
  
      send_email()
  </code></pre>
  
  <p>In my code above the <code>hostname</code> is of the format of an <code>ip_address</code>. When I execute this code I get error as <code>TimeoutError: 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>.</p>
  
  <p>I tried <code>server = smtplib.SMTP('123.45.678.9', local_hostname = 'mail.company.com')</code> as well but same error. If I try <code>server = smtplib.SMTP('mail.company.com')</code> then I get following error - <code>[Errno -2] Name or service not known</code>. How can send an email from within the lambda function?</p>