-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathHTMLmail.py
executable file
·68 lines (50 loc) · 1.36 KB
/
HTMLmail.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/python
import os
from appscript import *
import time, string
myHTML = """
<html>
<body>
<p>
This is a test message. <b>It works!</b>
</p>
<p>
This is another paragraph.
</p>
</body>
</html>
"""
def mailfromSafari(filename):
# open filename in Safari
S = app('Safari')
S.make(at=app.documents.before, new=k.document)
fn = u'file://'+filename
S.documents[1].source.set(myHTML)
return
S.documents[1].URL.set(fn)
S.activate()
# create mail message with HTML from Safari
SE = app(u'System Events')
SE.keystroke(u'i', using=k.command_down)
time.sleep(2)
S.documents[1].close()
time.sleep(1)
def fillmail(tomail = "who@somwhere.com", subject = "subject"):
app('Mail').activate()
SE = app(u'System Events')
SE.processes[u'Mail'].windows[1].scroll_areas[2].text_fields[1].value.set(tomail)
SE.processes[u'Mail'].windows[1].text_fields[1].value.set(subject)
def createHTMLMail(htmltext = myHTML):
filename = '/tmp/mailhtml.%s.html' % os.getpid()
tempfile = open(filename, "w")
try:
tempfile.write(htmltext)
finally:
tempfile.close()
mailfromSafari(filename)
os.remove(filename)
fillmail("clark@amanochocolate.com","subject")
def main():
createHTMLMail()
if __name__ == '__main__':
main()