/
notesmail.py
84 lines (72 loc) · 2.29 KB
/
notesmail.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import datetime
from win32com.client import DispatchEx
from win32com.client import makepy
from extract import Extract
makepy.GenerateFromTypeLibSpec('Lotus Domino Objects')
makepy.GenerateFromTypeLibSpec('Lotus Notes Automation Classes')
class NotesMail():
"""
发送读取邮件有关的操作
"""
def __init__(self, server, file):
"""Initialize
@param server
Server's name of Notes
@param file
Your data file, usually ends with '.nsf'
"""
self.session = DispatchEx('Notes.NotesSession')
self.server = self.session.GetEnvironmentString("MailServer", True)
self.db = self.session.GetDatabase(server, file)
self.db.OPENMAIL
self.myviews = []
def send_mail(self, receiver, subject, body=None):
"""发送邮件
@param receiver: 收件人
@param subject: 主题
@param body: 内容
"""
doc = self.db.CREATEDOCUMENT
doc.sendto = receiver
doc.Subject = subject
if body:
doc.Body = body
doc.SEND(0, receiver)
def get_views(self):
for view in self.db.Views:
if view.IsFolder:
self.myviews.append(view.name)
def get_documents(self, view_name):
"""
@return generator
"""
documents = []
folder = self.db.GetView(view_name)
if not folder:
raise Exception('Folder {0} not found. '.format(view_name))
document = folder.GetFirstDocument
while document:
documents.append(document)
document = folder.GetNextDocument(document)
return documents
def read_mail(self, view, attachment=False):
"""Read the latest mail
@param view
The view(fold) to access
@param attachment
Boolean, whether get attachment
@return, dict
Info of a mail
"""
result = {}
documents = self.get_documents(view)
latest_document = documents[-1:][0]
extra_obj = Extract(latest_document)
result = extra_obj.extract()
if attachment:
extra_obj.get_attachment()
return result
def main():
pass
if __name__ == '__main__':
main()