pythonemaildesktop-applicationxdgutils

How to open the user's preferred mail application on Linux?


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

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


Solution

  • The linux command to call would be xdg-email, part of the xdg-utils package, which is 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 e-mail composer".

    provided they've set up their default applications properly, it will open their default mail client. You can pass it arguments to fill in various mail fields (to, cc, subject, body etc.), as well as file names of the files to attach.

    From your python script you could call it using os.system() or the subprocess module..