Skip to content

Instantly share code, notes, and snippets.

@hideaki-t
Created July 4, 2014 05:12
Show Gist options
  • Save hideaki-t/c8a922f2a5b1f98a8bc5 to your computer and use it in GitHub Desktop.
Save hideaki-t/c8a922f2a5b1f98a8bc5 to your computer and use it in GitHub Desktop.

Revisions

  1. hideaki-t created this gist Jul 4, 2014.
    36 changes: 36 additions & 0 deletions send_to_kindle.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    import sys
    from outbox import Outbox, Email, Attachment
    from pathlib import Path


    if sys.version_info.major < 3:
    d = sys.getfilesystemencoding()

    def u(s):
    return unicode(s, d)
    else:
    def u(s):
    return s


    server_cfg = {
    'username': 'username',
    'password': 'password',
    'server': 'smtp_server',
    'port': '465',
    'mode': 'SSL',
    'debug': True
    }
    mail_cfg = {
    'recipients': ['[email protected]'],
    'subject': 'send to kindle',
    'body': 'Hello',
    'fields': {'From': '[email protected]'},
    'rfc2231': False
    }

    attachments = [
    Attachment(u(path.name), fileobj=path.open('rb')) for path in (Path(x) for x in sys.argv[1:])
    ]

    Outbox(**server_cfg).send(Email(**mail_cfg), attachments=attachments)