{"id":440,"date":"2026-11-26T17:02:00","date_gmt":"2026-11-26T16:02:00","guid":{"rendered":"https:\/\/www.netlabor.it\/?p=440"},"modified":"2026-11-27T10:53:57","modified_gmt":"2026-11-27T09:53:57","slug":"inviare-file-da-dolphin-a-thunderbird-con-un-click","status":"publish","type":"post","link":"https:\/\/www.netlabor.it\/en\/inviare-file-da-dolphin-a-thunderbird-con-un-click\/","title":{"rendered":"Send files from Dolphin to Thunderbird with a click"},"content":{"rendered":"\n<div class=\"wp-block-bogo-language-switcher\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">A small Python script + a <code>.desktop<\/code> file let you select one or more files\/folders in Dolphin, click \u201cSend by email\u201d, and immediately open a Thunderbird compose window with the attachments already prepared.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why it&#8217;s useful<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Time-saving:<\/strong> no copying into a temporary folder, no manual compression.<\/li>\n\n\n\n<li><strong>Full control:<\/strong> Thunderbird opens in draft\/compose mode; you write the recipient, subject, and body, then hit Send yourself.<\/li>\n\n\n\n<li><strong>Smart rules:<\/strong>\n<ul class=\"wp-block-list\">\n<li>Up to 5 files \u2192 individual attachments.<\/li>\n\n\n\n<li>More than 5 files or at least one folder \u2192 a single <code>selected.zip<\/code> archive containing everything.<\/li>\n\n\n\n<li>Paths inside the archive are relative, not absolute, so the zip file is \u201cclean\u201d and works anywhere.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Prerequisites<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>KDE Plasma desktop with Dolphin.<\/li>\n\n\n\n<li>Thunderbird installed and available in <code>PATH<\/code>.<\/li>\n\n\n\n<li>The <code>zip<\/code> utility (usually already installed).<\/li>\n\n\n\n<li>Python 3 (the helper script is written in Python).<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Installation<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">1. The helper script<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Copy the following script into an executable directory for your user, such as <code>~\/.local\/bin\/dolphin_thunderbird_send.py<\/code>, and adjust the <code>mailer<\/code> variable if needed:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/usr\/bin\/env python3\n\"\"\"\nDolphin service menu helper: prepares attachments from the selected items\nand opens a Betterbird compose window (no automatic sending).\n\nUsage:\n    dolphin_thunderbird_send.py &lt;selected-path-1> &#091;selected-path-2 ...]\n\nPackaging rules:\n    * If any selected item is a directory, or more than 5 files are selected,\n      all items are bundled into a single ZIP archive and attached once.\n    * Otherwise each selected file is attached individually.\n\"\"\"\n\nimport os\nimport subprocess\nimport sys\nimport shutil\nimport tempfile\nfrom pathlib import Path\nfrom urllib.parse import unquote, urlparse\n\nmailer = \"betterbird\"\n\ndef main() -> int:\n    # KDE passes the selected URLs\/paths as the remaining arguments.\n    selected_paths: list&#091;Path] = &#091;]\n    for arg in sys.argv&#091;1:]:\n        arg = arg.strip()\n        if not arg:\n            continue\n        if arg.startswith(\"file:\"):\n            parsed = urlparse(arg)\n            selected_paths.append(Path(unquote(parsed.path)))\n        else:\n            selected_paths.append(Path(arg))\n    if not selected_paths:\n        return 0\n    selected = &#091;p.expanduser().resolve() for p in selected_paths]\n\n    has_dir = any(p.is_dir() for p in selected)\n    file_count = sum(1 for p in selected if p.is_file())\n\n    attachments: list&#091;str] = &#091;]\n    tmpdir: Path | None = None\n\n    if has_dir or file_count > 5:\n        # Bundle everything into a single ZIP archive, storing only\n        # relative paths (no absolute paths) inside the archive.\n        tmpdir = Path(tempfile.mkdtemp(prefix=\"dolphin-thunderbird-\"))\n        zip_path = tmpdir \/ \"selected.zip\"\n\n        # Prepare a flat temp directory with only the item names (no full paths).\n        for p in selected:\n            if p.is_file():\n                # Copy the file using only its basename; if a file with the same name\n                # already exists, add a numerical suffix to avoid overwriting.\n                dest = tmpdir \/ p.name\n                counter = 1\n                while dest.exists():\n                    stem, ext = p.stem, p.suffix\n                    dest = tmpdir \/ f\"{stem}_{counter}{ext}\"\n                    counter += 1\n                shutil.copy2(p, dest)\n            elif p.is_dir():\n                # Copy the whole directory tree under the directory's basename.\n                dest_dir = tmpdir \/ p.name\n                if dest_dir.exists():\n                    shutil.rmtree(dest_dir)\n                shutil.copytree(p, dest_dir)\n\n        # Create the ZIP from inside the temp directory so that only the\n        # prepared relative paths are stored.\n        subprocess.run(&#091;\"zip\", \"-r\", str(zip_path), \".\"], cwd=tmpdir, check=True)\n        attachments = &#091;str(zip_path)]\n    else:\n        # Attach each file individually (no zip).\n        attachments = &#091;str(p) for p in selected if p.is_file()]\n\n    joined_att = ','.join(attachments)\n    attach_arg = f\"'{joined_att}'\"\n\n    subject = \"Files from Dolphin\"\n    body = \"Attachments prepared from Dolphin selection.\"\n    compose_str = (\n        f\"subject={subject},\"\n        f\"body={body},\"\n        f\"attachment={attach_arg}\"\n    )\n\n    try:\n        subprocess.run(&#091;mailer, \"-compose\", compose_str], check=True)\n    except FileNotFoundError:\n        print(f\"{mailer} not found in PATH\", file=sys.stderr)\n        return 1\n    except subprocess.CalledProcessError as exc:\n        print(f\"{mailer} exited with code {exc.returncode}\", file=sys.stderr)\n        return exc.returncode\n\n    return 0\n\nif __name__ == \"__main__\":\n    sys.exit(main())<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Make it executable:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>chmod +x ~\/.local\/bin\/dolphin_thunderbird_send.py\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">2. The KDE service menu<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Create (or overwrite) the file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>~\/.local\/share\/kio\/servicemenus\/dolphin-thunderbird-send.desktop\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">with this content:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#091;Desktop Entry]\nType=Service\nMimeType=inode\/directory;application\/octet-stream;\nActions=sendByEmail\n\n&#091;Desktop Action sendByEmail]\nName=Send by email\nName&#091;it]=Invia per email\nIcon=mail-send\nExec=\/home\/yourusername\/.local\/bin\/dolphin_thunderbird_send.py %U\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Replace <code>\/home\/yourusername\/<\/code> with the path to your home directory. Save the file: Dolphin will automatically pick up the new action; no need to restart Plasma.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How to use it<\/h3>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>Open Dolphin.<\/li>\n\n\n\n<li>Select one or more files, a folder, or a mix of both.<\/li>\n\n\n\n<li>Right-click the selection.<\/li>\n\n\n\n<li>Choose <strong>Send by email<\/strong> (or <em>Invia per email<\/em>, depending on your system language).<\/li>\n\n\n\n<li>Thunderbird opens with a new compose window; the attachments are already added.<\/li>\n\n\n\n<li>Fill in To, Subject, and Body, then click Send.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">How the script works<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The script receives the items selected in Dolphin via command-line arguments (<code>sys.argv[1:]<\/code>), because the <code>.desktop<\/code> file uses the <code>%U<\/code> placeholder.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The bundling logic works as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Check:<\/strong>\n<ul class=\"wp-block-list\">\n<li>If there is at least one directory or more than 5 files \u2192 a ZIP is needed.<\/li>\n\n\n\n<li>Otherwise \u2192 individual attachments.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Creating the ZIP (when needed):<\/strong>\n<ul class=\"wp-block-list\">\n<li>Each item is copied into a temporary directory using only its base name (no absolute path).<\/li>\n\n\n\n<li>If two items have the same name, a numeric suffix is added (<code>file_1.txt<\/code>).<\/li>\n\n\n\n<li><code>zip -r selected.zip .<\/code> runs inside that temporary directory, so the archive contains relative paths (<code>file.txt<\/code>, <code>docs\/<\/code>, \u2026) rather than <code>\/home\/user\/....<\/code><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Launching Thunderbird:<\/strong>\n<ul class=\"wp-block-list\">\n<li>A <code>compose_str<\/code> string is built like <code>subject=Files from Dolphin,body=...,attachment=selected.zip<\/code>.<\/li>\n\n\n\n<li><code>thunderbird -compose \"...\"<\/code> is executed, opening the compose window with the attachments already in place.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Behavior table<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><td><strong>Selection in Dolphin<\/strong><\/td><td><strong>What happens<\/strong><\/td><\/tr><\/thead><tbody><tr><td>Up to 5 files, no folders<\/td><td>Each file attached individually<\/td><\/tr><tr><td>More than 5 files, no folders<\/td><td>Single <code>selected.zip<\/code> archive with all files (relative names)<\/td><\/tr><tr><td>A folder is selected (even with few files)<\/td><td>Single <code>selected.zip<\/code> archive containing the folder and all files inside it<\/td><\/tr><tr><td>No items selected<\/td><td>No window is opened (script exits immediately)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Conclusion<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">With a few simple steps, you can turn Dolphin into a smart \u201csend by email button\u201d capable of creating clean ZIPs (without absolute paths) and leaving Thunderbird with just the job of composing the message. It is a lightweight solution, with no unusual dependencies, and designed specifically for the KDE environment.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A small Python script + a .desktop file let you select one or more files\/folders in Dolphin, click \u201cSend by email\u201d, and immediately open a Thunderbird compose window with the attachments already prepared. Why it&#8217;s useful Prerequisites Installation 1. The helper script Copy the following script into an executable directory for your user, such as [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"full-width-page-template.php","format":"standard","meta":{"_locale":"en_US","_original_post":"https:\/\/www.netlabor.it\/?p=436","footnotes":""},"categories":[6,7],"tags":[8,9],"class_list":["post-440","post","type-post","status-publish","format-standard","hentry","category-informatica","category-programmazione","tag-informatica","tag-programmazione","en-US","missing-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.netlabor.it\/wp-json\/wp\/v2\/posts\/440","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.netlabor.it\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.netlabor.it\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.netlabor.it\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.netlabor.it\/wp-json\/wp\/v2\/comments?post=440"}],"version-history":[{"count":3,"href":"https:\/\/www.netlabor.it\/wp-json\/wp\/v2\/posts\/440\/revisions"}],"predecessor-version":[{"id":454,"href":"https:\/\/www.netlabor.it\/wp-json\/wp\/v2\/posts\/440\/revisions\/454"}],"wp:attachment":[{"href":"https:\/\/www.netlabor.it\/wp-json\/wp\/v2\/media?parent=440"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.netlabor.it\/wp-json\/wp\/v2\/categories?post=440"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.netlabor.it\/wp-json\/wp\/v2\/tags?post=440"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}