O
O
Oleg Petrov2018-10-10 14:49:54
Python
Oleg Petrov, 2018-10-10 14:49:54

How to write the contents of the sheet separated by a space in the body of the letter?

Sending a letter, I want to insert a sheet into the body of the letter
How can I add the sheet sendcoins ['2','G'] and the sheet volumecoins_todaytoaverage = ['7','T'] in the body of the letter
Now:" AttributeError: 'list' object has no attribute 'encode'"

import smtplib
from email.mime.text import MIMEText
from email.header import Header

# Настройки
mail_sender = 'xxx'
mail_receiver = 'xxx'
username = 'xxx'
password = 'xxx'
server = smtplib.SMTP('smtp.mail.ru:587')

sendcoins = ['2','G']
volumecoins_todaytoaverage = ['7','T']
# Формируем тело письма
subject = u'Тестовый email от '# + mail_sender
body = sendcoins
msg = MIMEText(body, 'plain', 'utf-8')
msg['Subject'] = Header(subject, 'utf-8')

# Отпавляем письмо
server.starttls()
server.ehlo()
server.login(username, password)
server.sendmail(mail_sender, mail_receiver, msg.as_string())
server.quit()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadim Shatalov, 2018-10-10
@Smeilz1

body = 'sendcoins: {}, volumecoins_todaytoaverage: {}'.format(' '.join(sendcoins), ' '.join(volumecoins_todaytoaverage))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question