title: Sending an email to gmail based off a notification from Arduino to serial port
body: <p>So I am trying to do a plant monitoring environment project which I have the arduino/embedded side working. The idea is when it falls below a certain threshold in the sensors the embedded side sends a string via bluetooth module to serial ports which this python script is listening to. If the script detects one of the strings on the port it sends an email message to the inputted email. 
  However as it stands right now it doesn't seem to be sending the email off to the user inputted email, I am unsure if the issue lies in my send_email method or in the main loop itself but after filling in all the user input values it just loops forever doing nothing not even printing the No Email Sent case and I am currently unsure why. Additionally there was some issues with the getpass3 function and scrambling the password in terminal so for the time being I've switched to raw_input once I get the email send functioning I plan to switch back to the getpass3 and fix it as all it did before was type display the prompt for enter password and then hang at that point. </p>
  
  <p>This is my second program in python so it's entirely possible I've misinterpreted how some of these methods are called or passed but from what I've looked at in the documentation so far I don't see anything wrong on that side. I've gotten the adruino to send info across the serial port before, but there might be an issue with the bluetooth device pairing which I've noticed has happened before for reference the module is the HC-05 and I've gotten it to send the info across to TeraTerm before. </p>
  
  <pre><code>import time
  import serial
  import smtplib
  import colorama
  import getpass3
  
  useremail = raw_input("Enter your email ")
  # getpass3.set_echo = '#'
  # userpass = getpass3.getpass("Enter your password: ")
  userpass = raw_input("Enter your password ")
  usercom = raw_input("Please Enter COMPORT: ").upper()
  print usercom
  
  TO = useremail
  GMAIL_USER = useremail
  GMAIL_PASS = userpass #plaintext need to get getpass3 working i hate this way
  
  SUBJECT = 'Plant Environment Needs Attention'
  TEXT1 = 'Low Light Levels Detected in the Enclosure'
  TEXT2 = 'Low Mositure in the Soil Detected in the Enclosure'
  TEXT3 = 'Temperature Outside of Safe Range in Enclosure'
  TEXT4 = 'Humidity Outside of Safe Range in Enclosure'
  
  ser = serial.Serial(usercom, 9600) #seems to always be COM9 on my PC can adjust as needed
  
  def send_email(TEXT):
      print("Sending Email")
      #SMTP server setup
      smtpserver = smtplib.SMTP("smtp.gmail.com",587)
      smtpserver.ehlo()
      smtpserver.starttls()
      smtpserver.ehlo()
      #login to gmail can potentially add diff email client if wanted
      smtpserver.login(GMAIL_USER, GMAIL_PASS)
      header = 'To:' + TO + '\n' + 'From: ' + GMAIL_USER
      header = header + '\n' + 'Subject:' + SUBJECT + '\n'
      # #form the diff cases here based off if its temp hum ect
      print header
      msg = header + '\n' + TEXT + ' \n\n'
      #send email and close server for security reasons
      smtpserver.sendmail(GMAIL_USER, TO, msg)
      smtpserver.close()
  
  # just do it forever
  while True:
      message = ser.readline()
      print(message)
      #big brained implamentation
      #L = light
      if message[0] == 'L' :
          send_email(TEXT1)
          print("Email Sent")
      #S = Soil Moisutre
      if message[0] == 'S' :
          send_email(TEXT2)
          print("Email Sent")
      #T = temp
      if message[0] == 'T' :
          send_email(TEXT3)
          print("Email Sent")
      #H = Humidity
      if message[0] == 'H' :
          print("Email Sent")
          send_email(TEXT4)
      else:
          print("No Email Sent")
      time.sleep(0.5)
  </code></pre>