Attach a file from the filesystem. Set the mimetype to DEFAULT_ATTACHMENT_MIME_TYPE if it isn't specified and cannot be guessed. For a text/* mimetype (guessed or specified), decode the file's content as UTF-8. If that fails, set the mimetype to DEF
(self, path, mimetype=None)
| 463 | self.attachments.append(EmailAttachment(filename, content, mimetype)) |
| 464 | |
| 465 | def attach_file(self, path, mimetype=None): |
| 466 | """ |
| 467 | Attach a file from the filesystem. |
| 468 | |
| 469 | Set the mimetype to DEFAULT_ATTACHMENT_MIME_TYPE if it isn't specified |
| 470 | and cannot be guessed. |
| 471 | |
| 472 | For a text/* mimetype (guessed or specified), decode the file's content |
| 473 | as UTF-8. If that fails, set the mimetype to |
| 474 | DEFAULT_ATTACHMENT_MIME_TYPE and don't decode the content. |
| 475 | """ |
| 476 | path = Path(path) |
| 477 | with path.open("rb") as file: |
| 478 | content = file.read() |
| 479 | self.attach(path.name, content, mimetype) |
| 480 | |
| 481 | def _add_bodies(self, msg): |
| 482 | if self.body or not self.attachments: |