-
Notifications
You must be signed in to change notification settings - Fork 1
/
mail.py
39 lines (31 loc) · 1003 Bytes
/
mail.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import utils
import applescript
ASCRIPT = """\
tell application "Mail"
activate
--Create the message
set theMessage to make new outgoing message with properties {{subject:%(subject)s, content:%(body)s, visible:true}}
--Set a recipient
tell theMessage
%(recipents_commands)s
%(send)s
end tell
end tell
"""
def send_msg (module, subject, send=False):
# Addresses
cmds = []
for address in module.TO:
name, email = address
cmds.append (applescript.email_to_as (name, email, 'to'))
for address in module.CC:
name, email = address
cmds.append (applescript.email_to_as (name, email, 'cc'))
# Build message
send_cmd = ('', 'send')[send]
ascript = ASCRIPT %({'recipents_commands': '\n'.join(cmds),
'body': applescript.asquote(module.BODY),
'subject': applescript.asquote(subject),
'send': send_cmd})
# Run it
applescript.asrun (ascript)