1

When I try to use mailto: with the webbrowser Python module

webbrowser.open_new("mailto:")

a new browser window is opened with one tab but "mailto" is not run if the default browser for webbrowser is Chrome.

(Alternative code with the same result:

wb_controller_gc = webbrowser.get("google-chrome")
wb_controller_gc.open_new("mailto:")

)

If I try to do the same thing with Firefox

wb_controller_ff = webbrowser.get("firefox")
wb_controller_ff.open_new("mailto:")

there is no problem: A new Firefox window is opened with two tabs and the default mail client is started.

Other things that I've tried:

  • Simply entering "mailto:" into the address bar in Chrome: No problem
  • open (with and without new=1), open_new, open_new_tab: Doesn't help

My setup:

  • OS: Lubuntu 16.04 (64 bit)
  • Python version: 3.5.2

(I tried to test this for Windows 7 as well but unfortunately webbrowser.get could not find the Chrome browser on the computer that I borrowed, even though I tried both "chrome" and "google-chrome" from this table)

Could this problem have something to do with the OS? Is there a workaround that you can recommend? Grateful for help!

sunyata
  • 1,843
  • 5
  • 27
  • 41
  • [You have to register ProtocolHandler for mailto in Chrome.](https://developers.google.com/web/updates/2012/02/Getting-Gmail-to-handle-all-mailto-links-with-registerProtocolHandler) Some folks solve this with [a plugin](https://chrome.google.com/webstore/detail/mailto-for-gmail/dgkkmcknielgdhebimdnfahpipajcpjn/reviews?hl=en-GB). But this is obviously not ideal since you can't control client environment. – Dan Feb 21 '17 at 19:06
  • @Dan: Thank you for the comment. In my case I don't want to open gmail, I just want the Chrome browser to (more generally) get and handle the mailto link. I know that Chrome can handle mailto if I give it to Chrome directly (typing it into the address bar), but when I try to send it through `webbrowser.open_new` there is a problem – sunyata Feb 21 '17 at 19:20
  • See http://stackoverflow.com/questions/3059412/python-open-default-mail-client-using-mailto-with-multiple-recipients (hint: this approach doesn't work) – Dan Feb 22 '17 at 05:26
  • Best I could find is http://translate.svn.sourceforge.net/viewvc/translate/src/trunk/virtaal/virtaal/support/openmailto.py?view=markup – Dan Feb 22 '17 at 05:27
  • @Dan: Thank you for your effort in trying to help. I tried the sourceforge code (with Python version 2) but unfortunately that gave the same problem as in the question (Chrome browser is started with an empty tab but nothing else happens). The main answer in the SO link you gave suggest using an SMTP server and asking the user for login info, but that's unfortunately too much hassle for my users :( – sunyata Feb 22 '17 at 11:13

0 Answers0