Reputation: 303
I use this command to send a logfile with Thunderbird:
thunderbird -compose "subject='test',to='[email protected]',body=$output,attachment='/home/test/scan.log'"
That launches and shows Thunderbird's prefilled edit-message-window and I have to press the Send button manually.
How can I send email automatically?
Upvotes: 9
Views: 28591
Reputation: 588
Actually, it is possible, using xdotool
. Though not "proper", it is possible.
You can (modify to suit your purpose) and save this to ~/bin/send-mail
#!/bin/bash
output='testing'
thunderbird -compose "subject='test mail',to='[email protected]',body=$output" &
sleep 2 # Wait for the window to open
xdotool mousemove 55 105 # Find the exact position of the send button manually
&
will run this second command parallel to the one before
sleep 0.25 # Might not be needed
xdotool click 1 # Click it
echo "Done!"
Make it executable:
chmod +x bin/send-mail
Additionally, add it to your cron job. But this sure can be risky.
You need to set xorg as your windowing system! xdotool
works with xorg not with wayland windowing system!
Upvotes: 5
Reputation: 1
I am going to share part of my script that downloads a file from google drive GNOME Virtual file system convert part of it as pdf and sends it through thunderbird
you need to set xorg as your window system for xdotool to work, as it will not work if wayland is set as your window system in ubuntu.
# Step 8: Send email with attachment
thunderbird -compose "subject='Comprobante de pago',to='$EMAIL',body='Buenas noches, envío comprobante de pago mes relacionado en el recibo adjunto.
Gracias y feliz día.
Cristian Beltrán
3143530535',attachment='$DOWNLOAD_DIR/$PDF_NAME'" &
# Step 9: Wait for Thunderbird window and simulate send
sleep 2
xdotool key alt key f key d #this is the keyboard shortcut to send.
wait
# Step 10: Cleanup
rm "$DOWNLOAD_DIR/$PDF_NAME" "$DOWNLOAD_DIR/$FILE_NAME"
1 ----&----- for Background Execution:
Running thunderbird with & allows it to execute in the background, which is crucial for continuing the script without blocking.
2 ----wait---- for Synchronization:
After triggering xdotool to simulate the "Send" action, wait ensures that the script doesn't terminate prematurely, especially before Thunderbird finishes processing.
Important Note on Xorg:
As highlighted, xdotool depends on Xorg for interacting with graphical windows. If Wayland is active (the default on newer Ubuntu installations), xdotool won't work. This means users must set their session to Xorg.
Upvotes: 0
Reputation: 39
Thunderbird doesn't support automatically sending an email using the command line (i.e. non interactively). This question was answered here - https://support.mozilla.org/en-US/questions/1144493
It suggests you communicate directly with the relevant SMTP server instead of using a mail client like Thunderbird.
Possibly using PHP -http://www.inmotionhosting.com/support/website/sending-email-from-site/using-the-php-mail-function-to-send-emails
Upvotes: 3