On 11Nov2014 17:35, Ethan Furman <et...@stoneleaf.us> wrote:
Okay, the explicit Python question:  Clicking on a mail link in a web browser 
can start an external program.  I would like that external program to be a 
Python script that: opens a new tab in the currently running browser (or a new 
default browser window), loads up the default web mail client (or one specified 
if there is no way to know/have a default), navigates to the compose pane (or 
starts there if possible), enters in the email address from the link that was 
passed to it, and, if not too much more, move the cursor to the subject field.

Surely this can be done in Python.

Yes and no. It is dependent on how much control GMail allows you from outside.

A quick web search on "open gmail compose using url" led me to this discussion:

 http://stackoverflow.com/a/8852679

which espouses this URL template:

 
https://mail.google.com/mail/?view=cm&fs=1&to=some...@example.com&su=SUBJECT&body=BODY&bcc=someone.e...@example.com

which I have tested, and it works. It does require your browser to be logged into GMail already.

Given that, you just need a Python script that can be invoked as a standard browser external mail client accepting the mailto: URL from the browser. Decode the URL into to/subject/etc and then open the right URL using the above template.

As an exercise, I wrote a short shell script:

 https://bitbucket.org/cameron_simpson/css/src/tip/bin-cs/gmail

which I would invoke from a shell prompt as:

 gmail -s "subject line here" j...@blogs.com b...@ben.com ...

Adapting it to (a) Python (b) accept a mailto:URL and decoding its fields and (c) opening that URL from inside Python using the "webbrowser" module's:

 https://docs.python.org/3/library/webbrowser.html#module-webbrowser

"open" function I leave as an exercise for the reader. Should take less thatn an hour I'd hope.

Cheers,
Cameron Simpson <c...@zip.com.au>

Perhaps this morning there were only three Euclidean solids, but god changed
its mind retroactively at lunchtime, remaking the whole history of the
universe.  That's the way it is with omnipotent beings.
       - mi...@apple.com (Mikel Evins)
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to