title: How to email variable value using raspberry pi and smtplib
body: <p>I am working on this project where i have 3 string variables which I want to email their values to an email address. I was able to email a plain text message; however, I couldn't include these variables values in. Below is my codes: </p>
  
  <pre><code>import serial
  import smtplib
  import time
  
  serialport = serial.Serial('/dev/ttyUSB0', 115200, timeout = 0.5)
  user= 'user@gmail.com'
  password= 'password'
  receiver= 'receiver@gmail.com
  subject= 'Solar tracker status'
  header = 'To: ' + email + '\n' + 'From: ' + email + '\n' + 'Subject: ' + 
  subject
  while True:
      line = serialport.readline()
      result = line.find(";")
      if result &gt; 0:
              str = line.split(";")
              volt=str[0]
              power=str[1]
              temp=str[2]
              body = "\n" + + "Voltage: " + volt + "\n" + "Power: " + power + "\n" + "Temp: " + temp
              print header + '\n' + body
              s=smtplib.SMTP('smtp.gmail.com',587)
              s.ehlo()
              s.starttls()
              s.ehlo()
              s.login(email, password)
              s.sendmail(email, email, header + '\n\n' + body)
              s.quit
  </code></pre>
  
  <p>When running this script, i got this error message :   </p>
  
  <pre><code>File "testserial.py", line 23, in &lt;module&gt;
      body = "\n" + + "Voltage: " + volt
  TypeError: bad operand type for unary +: 'str'
  </code></pre>
  
  <p>I have tried converting the variable into string using str(volt), then got this error message: </p>
  
  <pre><code>File "testserial.py", line 23, in &lt;module&gt;
      str(volt)
  TypeError: 'list' object is not callable
  </code></pre>
  
  <p>I can't understand this because they are originally in string format since i was able to write them into a text file using %s without having to convert it. </p>
  
  <p>I think i just don't know how to pass a variable into the body of the email. 
  Please help!</p>