Skip to content

Instantly share code, notes, and snippets.

@xuhdev
Last active Dec 14, 2016
Embed
What would you like to do?
#!/usr/bin/python3
# https://www.topbug.net/blog/2016/12/13/send-git-patches-with-gui-email-clients/
import sys
import webbrowser
try:
from urllib.parse import quote # python 3
except:
from urllib import quote # python 2
SUBJECT_PREFIX = 'Subject:'
if len(sys.argv) >= 2:
to = sys.argv[1]
else:
to = ''
# Determine the subject
for line in sys.stdin:
line = line.strip()
if line.startswith(SUBJECT_PREFIX):
subject = line[len(SUBJECT_PREFIX):].strip()
break
# Determine the body
body = ''
for line in sys.stdin:
body += line
webbrowser.open('mailto:?To={}&Subject={}&Body={}'.format(quote(to), quote(subject), quote(body)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment