-1

I have the next function:

hostname = os.uname()[1]

def sendmail(sender, receiver, content, user=None, password=None, hostname='localhost', port=25,ssl=False):
smt_server = 'localhost'
port = '25'
sender = 'jenkins@jenkins.com'
receiver = 'test@test.es'

content = "I need to show hostname here" , hostname , "Done."

msg = MIMEText(content)
msg['From'] = sender
msg['To'] = receiver
msg['Subject'] = 'Simple app script'

try:
   s = smtplib.SMTP('localhost', port )
   s.sendmail('jenkins@jenkins.com', 'test@test.es', content)
   s.quit()
   print "Succesfully sent email"
except SMTPException:
   print "Error: fail to send email"

Actual result:

AttributeError: 'tuple' object has no attribute 'encode'

Expected result:

The body message of the mail have to be:

I need to show hostname here MyHostname Done.

I'm not sure if i'm using the rigth way, could you help me?

Thanks

hmar
  • 107
  • 2
  • 13
  • Possible duplicate of [How can strings be concatenated?](https://stackoverflow.com/questions/2711579/how-can-strings-be-concatenated) – Sayse Jun 11 '19 at 09:31

2 Answers2

1

You can add strings:

content = "I need to show hostname here" + hostname + "Done."
ForceBru
  • 43,482
  • 10
  • 63
  • 98
1

Try this to make content one string.

content = "I need to show hostname here " + hostname + " Done."
Toni Sredanović
  • 2,280
  • 1
  • 11
  • 13