Guest User

Untitled

a guest
Dec 14th, 2017
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. From test-sender@example.com
  2. From: test-sender@example.com
  3. To: test-recipient@example.com
  4. Subject: test simple message
  5.  
  6. It's a test.
  7.  
  8. -- Best regards.
  9.  
  10. text = ''
  11. for attachment in self.attachments_pool:
  12. text+='Removed ' + attachment.getFilename() +' with hash: ' + attachment.getHash() + 'n'
  13. text = MIMEText(text, 'plain')
  14. self.msg.attach(text)
  15.  
  16. Traceback (most recent call last):
  17. File "/usr/lib/python3.5/email/message.py", line 209, in attach
  18. self._payload.append(payload)
  19. AttributeError: 'str' object has no attribute 'append'
  20.  
  21. During handling of the above exception, another exception occurred:
  22.  
  23. Traceback (most recent call last):
  24. File "msg_parser.py", line 386, in <module>
  25. raise e
  26. File "msg_parser.py", line 376, in <module>
  27. main()
  28. File "msg_parser.py", line 369, in main
  29. msg_handler.handle()
  30. File "msg_parser.py", line 329, in handle
  31. self.msg.attach(text)
  32. File "/usr/lib/python3.5/email/message.py", line 211, in attach
  33. raise TypeError("Attach is not valid on a message with a"
  34. TypeError: Attach is not valid on a message with a non-multipart payload
  35.  
  36. #!/usr/bin/env python3
  37. import email.policy
  38.  
  39. msg = email.message_from_string("""From test-sender@example.com
  40. From: test-sender@example.com
  41. To: test-recipient@example.com
  42. Subject: test simple message
  43.  
  44. It's a test.
  45.  
  46. -- Best regards.""", policy=email.policy.default)
  47.  
  48. msg.set_content("Заменили текст.")
  49.  
  50. print(msg)
  51.  
  52. From: test-sender@example.com
  53. To: test-recipient@example.com
  54. Subject: test simple message
  55. Content-Type: text/plain; charset="utf-8"
  56. Content-Transfer-Encoding: base64
  57. MIME-Version: 1.0
  58.  
  59. 0JfQsNC80LXQvdC40LvQuCDRgtC10LrRgdGCLgo=
Add Comment
Please, Sign In to add comment