import sys
import os
import shutil
import emails # sudo pip install emails
from emails.template import JinjaTemplate as T
file = open('email.txt', 'r') # reading email string from the user`s .txt
# file
# userm = str(file.read()) # allocating variable and casting the read
# result, if required
userm = file.read() # read the file content, no variable casting in this
# case
print (userm) # checking the content
message = emails.html(subject=T('Data processing request{{ billno }}'),
html=T('<p>Dear {{ name }}! Your genomics data have been processed,
download the attached files and look at your genome annotations, please'),
mail_from=('Genomics data processor', 'XXXXXXXXXXX'))
message.send(to=('Scientist', userm), # second argument is a email of the
user coming from the .txt file
render={'name': 'Scientist', 'billno': '777'})
message.attach(data=open('processedfiles.zip', 'rb'),
filename='YourGenomeProcessedAnnotations.zip', content_disposition='inline')
m = message.as_message()
s = message.as_string()
r = message.send(to=('Scientist', userm), # second argument is a email of
the user coming from the .txt file
render={'name': 'Scientist'},
smtp={'host':'smtp.yandex.com', 'port': 465, 'ssl': True, 'user':
'XXXXXXXXXX', 'password': 'XXXXXXX'}) # Write your own credentials here
assert r.status_code == 250
Эти коды работают в Windows, однако сбой в Linux Mint вызывает ошибку BadHeaderError, как это исправить, пожалуйста?
Это хорошо сработало месяц назад в Linux, но теперь это не так,не знаю причин.Пробовал на другом Linux, ошибка снова та же.
Вот журнал:
Traceback (most recent call last):
File "BACK_END_PYTHON.py", line 29, in <module>
render={'name': 'Scientist', 'billno': '777'})
File "/usr/local/lib/python2.7/dist-packages/emails/message.py", line 404, in send
return smtp.sendmail(**params)
File "/usr/local/lib/python2.7/dist-packages/emails/backend/smtp/backend.py", line 117, in sendmail
msg=msg.as_string(),
File "/usr/local/lib/python2.7/dist-packages/emails/message.py", line 337, in as_string
r = to_native(self.build_message(message_cls=message_cls).as_string())
File "/usr/local/lib/python2.7/dist-packages/emails/message.py", line 284, in build_message
msg = self._build_root_message(message_cls)
File "/usr/local/lib/python2.7/dist-packages/emails/message.py", line 258, in _build_root_message
self.set_header(msg, 'To', ", ".join([self.encode_address_header(addr) for addr in mail_to]), encode=False)
File "/usr/local/lib/python2.7/dist-packages/emails/message.py", line 227, in set_header
raise BadHeaderError("Header values can't contain newlines (got %r for header %r)" % (value, key))
emails.exc.BadHeaderError: Header values can't contain newlines (got u'Scientist <XXXXXXXXXX\n>' for header u'To')
(программа вышла с кодом: 1) Нажмите return для продолжения