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': ['to@example.com'], 'subject': 'send to kindle', 'body': 'Hello', 'fields': {'From': 'from@example.com'}, '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)