Binary file open mode in examples. Fixes #58

This commit is contained in:
Sergey Lavrinenko 2015-10-15 14:11:11 +03:00
parent 13fb381db4
commit b0717cef42
3 changed files with 5 additions and 5 deletions

View File

@ -28,8 +28,8 @@ Attach files or inline images:
.. code-block:: python
message.attach(data=open('event.ics'), filename='Event.ics')
message.attach(data=open('image.png'), filename='image.png',
message.attach(data=open('event.ics', 'rb'), filename='Event.ics')
message.attach(data=open('image.png', 'rb'), filename='image.png',
content_disposition='inline')
Use templates:

View File

@ -11,7 +11,7 @@ Modern email handling in python.
text=T("Build passed: {{ project_name }} ..."),
subject=T("Passed: {{ project_name }}#{{ build_id }}"),
mail_from=("CI", "ci@mycompany.com"))
m.attach(filename="icon.png", content_disposition="inline", data=open("icon.png"))
m.attach(filename="icon.png", content_disposition="inline", data=open("icon.png", "rb"))
response = m.send(render={"project_name": "user/project1", "build_id": 121},
to='somebody@mycompany.com',
smtp={"host":"mx.mycompany.com", "port": 25})

View File

@ -16,7 +16,7 @@ Code example to make images inline:
.. code-block:: python
>>> message = emails.Message(html="<img src='promo.png'>")
>>> message.attach(filename='promo.png', data=open('promo.png'))
>>> message.attach(filename='promo.png', data=open('promo.png', 'rb'))
>>> message.attachments['promo.png'].is_inline = True
>>> message.transformer.synchronize_inline_images()
>>> message.transformer.save()
@ -41,7 +41,7 @@ Load from zipfile or directory:
.. code-block:: python
message = emails.loader.from_zipfile(open('design_pack.zip'))
message = emails.loader.from_zipfile(open('design_pack.zip', 'rb'))
message = emails.loader.from_directory('/home/user/design_pack')
Zipfile and directory loaders require at least one html file (with "html" extension).