How to open a preferred mail application for users on Linux?

I wrote a simple custom GUI script with python-gtk. Now I want to give the user a button to send email with an attachment.

The script runs on Linux desktops. Is there a way to open the user's preferred email application and attach the file?

+5
source share
3 answers

The linux command to invoke will be xdg-email , part of the xdg-utils package found on most Linux desktops (at least by default on arch, debian, ubuntu).

xdg-email is a "command line tool for sending mail using the user's preferred email composer."

if they correctly configured their default applications, it will open the default email client. You can pass it to the arguments to fill in various mail fields (in, cc, subject, body, etc.), as well as the file names of the attached files.

From your python script, you can call it using os.system () or a subprocess module.

+3
source

You can use the webbrowser module to open the url.
You can also use the mailto protocol so that the webbrowser opens the default mail client of the system, if available.

Here is a simple example:

 import webbrowser webbrowser.open("mailto: test@example.com ?subject=Hello World") 

Caution, lack of investment support. The mailto protocol does not support attachments. Some clients support (according to google) the non-standard attribute attachment=PATH . But I could not really confirm this.

There are ways that different email clients open an email window with an attachment, but this is different between each client. Also, I don’t know of any standard way to determine which email program is installed by default.

You can also check wikipedia for more information.

+3
source

this is how you install the user agent

  settings = webkit.WebSettings() settings.set_property('user-agent', 'iPad') webview.set_settings(settings) 

and for attaching images take a look at this script to get an idea

http://pygtk.org/pygtk2tutorial/examples/images.py

It is not certain, but I hope this helps.

-2
source

Source: https://habr.com/ru/post/1208077/


All Articles