问题
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?
回答1:
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..
回答2:
You can leverage the webbrowser
module to open a URL.
You can also leverage the mailto protocol to have the webbrowser open the system default mail client if available.
Here is a simple example:
import webbrowser
webbrowser.open("mailto:test@example.com?subject=Hello World")
Caveat, no support for attachments. The mailto protocol doesn't offer support for attachments. Some clients support (according to google) the nonstandard attribute attachment=PATH
. But I haven't been able to actually confirm this.
There are ways for various email clients to open an email compose window with an attachment but this differs between each client. Also I don't know of any standard way to determine what mail program is set as default.
For more information you can also check wikipedia
回答3:
this is how you set 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
this isn't definite but I hope it helps.
来源:https://stackoverflow.com/questions/27236963/how-to-open-the-users-preferred-mail-application-on-linux