Python: open Thunderbird to write new mail with file attached
I would like to open Thunderbird on Debian and Windows with a file attachment for a new mail.
So, I would like to do the same as in this thread, but the posted solution does not work:
Open Python email client with attachment
I have the same problem as user2686223. The file will not be attached to mail. Can anyone help me with this?
Maybe with a different solution?
EDIT: This now works:
import os
os.system("thunderbird -compose to='test@test.de',subject='subject',body='body',attachment='/path/to/file'")
source to share
Start Thunderbird with the "-compose" command line argument. More on this at http://kb.mozillazine.org/Command_line_arguments_%28Thunderbird%29
source to share
Using the information from mozillazine listed above I was able to get this to work with Python 2.7 on Windows 7
import subprocess
tbirdPath = r'c:\Program Files (x86)\Mozilla Thunderbird\thunderbird.exe'
to = 'recipiant@example.com'
subject = 'Hello'
body = '<html><body><h1>Header</h1>This is the body<br></body></html>'
composeCommand = 'format=html,to={},subject={},body={}'.format(to, subject, body)
subprocess.Popen([tbirdPath, '-compose', composeCommand])
source to share
Thunderbird with the "-compose" command line argument works great unless you want to add more than one item for one argument, for example two email addresses in the cc field. In accordance with:
http://kb.mozillazine.org/Command_line_arguments_%28Thunderbird%29
Double quotes enclose the complete comma-separated list of arguments passed to "-compose", while single quotes are used to group items by the same argument. Example:
thunderbird -compose "to = 'john @ example.com, kathy @ example.com', cc = 'britney @ example.com', subject = 'dinner', body = 'How about dinner tonight?', app = ' C: \ Temp \ Info.doc, C: \ Temp \ food.doc "
However, I need double quotes to pass the command line argument to os.system. Anyone have any ideas how to solve this?
source to share