Skip to content

Instantly share code, notes, and snippets.

@hideaki-t
Created July 4, 2014 05:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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.
send to kindle
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment