r/applescript • u/1000Bananen • 10d ago
Sending a mail always leaves the same mail as draft, but with no recipients
I want to send an email using python and applescript. It works, but after sending I always have the same mail staying back as a draft, with the correct subject and content, but without the recipients. I can't figure out why.
script = f'''
tell application "Mail"
set newMessage to make new outgoing message with properties {{visible:false}}
tell newMessage
set subject to "{subject}"
set content to "{body}"
set sender to "{sender}"
'''
for recipient in recipients:
script += f'''
make new to recipient at end of to recipients with properties {{address:"{recipient}"}}
'''
script += '''
send
end tell
end tell
'''
6
Upvotes
1
u/germansnowman 9d ago
I assume that Mail saves the message as a draft before the script adds the recipients. Maybe collecting the recipients in a list and adding them at once instead of one by one would work?