PyEmailerAJM 0.1__tar.gz → 1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {PyEmailerAJM-0.1 → PyEmailerAJM-1.1}/PKG-INFO +2 -2
- {PyEmailerAJM-0.1 → PyEmailerAJM-1.1}/PyEmailerAJM/PyEmailerAJM.py +90 -13
- {PyEmailerAJM-0.1 → PyEmailerAJM-1.1}/PyEmailerAJM.egg-info/PKG-INFO +2 -2
- PyEmailerAJM-1.1/README.md +8 -0
- {PyEmailerAJM-0.1 → PyEmailerAJM-1.1}/setup.py +2 -2
- PyEmailerAJM-0.1/README.md +0 -8
- {PyEmailerAJM-0.1 → PyEmailerAJM-1.1}/LICENSE.txt +0 -0
- {PyEmailerAJM-0.1 → PyEmailerAJM-1.1}/PyEmailerAJM/__init__.py +0 -0
- {PyEmailerAJM-0.1 → PyEmailerAJM-1.1}/PyEmailerAJM.egg-info/SOURCES.txt +0 -0
- {PyEmailerAJM-0.1 → PyEmailerAJM-1.1}/PyEmailerAJM.egg-info/dependency_links.txt +0 -0
- {PyEmailerAJM-0.1 → PyEmailerAJM-1.1}/PyEmailerAJM.egg-info/requires.txt +0 -0
- {PyEmailerAJM-0.1 → PyEmailerAJM-1.1}/PyEmailerAJM.egg-info/top_level.txt +0 -0
- {PyEmailerAJM-0.1 → PyEmailerAJM-1.1}/setup.cfg +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: PyEmailerAJM
|
|
3
|
-
Version:
|
|
3
|
+
Version: 1.1
|
|
4
4
|
Summary: Allows for automating sending Email with the Outlook Desktop client. Future releases will add more client support
|
|
5
5
|
Home-page: https://github.com/amcsparron2793-Water/PyEmailer
|
|
6
6
|
Author: Amcsparron
|
|
7
7
|
Author-email: amcsparron@albanyny.gov
|
|
8
8
|
License: MIT License
|
|
9
|
-
Download-URL: https://github.com/amcsparron2793-Water/PyEmailer/archive/refs/tags/
|
|
9
|
+
Download-URL: https://github.com/amcsparron2793-Water/PyEmailer/archive/refs/tags/1.1.tar.gz
|
|
10
10
|
Keywords: Outlook,Email,Automation
|
|
11
11
|
Platform: UNKNOWN
|
|
12
12
|
License-File: LICENSE.txt
|
|
@@ -4,6 +4,7 @@ PyEmailerAJM.py
|
|
|
4
4
|
|
|
5
5
|
install win32 with pip install pywin32
|
|
6
6
|
"""
|
|
7
|
+
from os.path import isfile, abspath, isabs, join
|
|
7
8
|
|
|
8
9
|
# imports
|
|
9
10
|
|
|
@@ -40,17 +41,102 @@ class PyEmailer:
|
|
|
40
41
|
self._recipient = None
|
|
41
42
|
self._subject = None
|
|
42
43
|
self._text = None
|
|
44
|
+
self.read_folder = None
|
|
43
45
|
|
|
44
46
|
try:
|
|
45
47
|
self.email_app = win32.Dispatch(self.email_app_name)
|
|
48
|
+
self._mapi_ns = self.email_app.GetNamespace('MAPI')
|
|
46
49
|
self.email = self.email_app.CreateItem(0)
|
|
47
50
|
except com_error as e:
|
|
48
51
|
self._logger.error(e, exc_info=True)
|
|
49
52
|
raise e
|
|
50
53
|
|
|
51
|
-
def
|
|
54
|
+
def _GetReadFolder(self, email_dir_index: int = 6):
|
|
55
|
+
# 6 = inbox
|
|
56
|
+
self.read_folder = self._mapi_ns.GetDefaultFolder(email_dir_index)
|
|
57
|
+
return self.read_folder
|
|
58
|
+
|
|
59
|
+
def GetMessages(self, folder_index=None):
|
|
60
|
+
if isinstance(folder_index, int):
|
|
61
|
+
self.read_folder = self._GetReadFolder(folder_index)
|
|
62
|
+
elif not folder_index and self.read_folder:
|
|
63
|
+
pass
|
|
64
|
+
elif not folder_index:
|
|
65
|
+
self.read_folder = self._GetReadFolder()
|
|
66
|
+
else:
|
|
67
|
+
try:
|
|
68
|
+
raise TypeError("folder_index must be an integer or self.read_folder must be defined")
|
|
69
|
+
except TypeError as e:
|
|
70
|
+
self._logger.error(e, exc_info=True)
|
|
71
|
+
raise e
|
|
72
|
+
return self.read_folder.Items
|
|
73
|
+
|
|
74
|
+
def GetEmailMessageBody(self, msg):
|
|
75
|
+
"""message = messages.GetLast()"""
|
|
76
|
+
body_content = msg.body
|
|
77
|
+
if body_content:
|
|
78
|
+
return body_content
|
|
79
|
+
else:
|
|
80
|
+
try:
|
|
81
|
+
raise ValueError("This message has no body.")
|
|
82
|
+
except ValueError as e:
|
|
83
|
+
self._logger.error(e, exc_info=True)
|
|
84
|
+
raise e
|
|
85
|
+
|
|
86
|
+
def FindMsgBySubject(self, subject: str) -> list:
|
|
87
|
+
matched_messages = []
|
|
88
|
+
for message in self.GetMessages():
|
|
89
|
+
if message.Subject == subject:
|
|
90
|
+
matched_messages.append(message)
|
|
91
|
+
return matched_messages
|
|
92
|
+
|
|
93
|
+
def SaveAllEmailAttachments(self, msg, save_dir_path):
|
|
94
|
+
attachments = msg.Attachments
|
|
95
|
+
for attachment in attachments:
|
|
96
|
+
full_save_path = join(save_dir_path, str(attachment))
|
|
97
|
+
try:
|
|
98
|
+
attachment.SaveAsFile(full_save_path)
|
|
99
|
+
self._logger.debug(f"{full_save_path} saved from email with subject {msg.subject}")
|
|
100
|
+
except Exception as e:
|
|
101
|
+
self._logger.error(e, exc_info=True)
|
|
102
|
+
raise e
|
|
103
|
+
|
|
104
|
+
def SetupEmail(self, recipient: str, subject: str, text: str, attachments: list = None):
|
|
105
|
+
def _validate_attachments():
|
|
106
|
+
if attachments:
|
|
107
|
+
if isinstance(attachments, list):
|
|
108
|
+
for a in attachments:
|
|
109
|
+
if isfile(a):
|
|
110
|
+
if isabs(a):
|
|
111
|
+
self.email.Attachments.Add(a)
|
|
112
|
+
else:
|
|
113
|
+
a = abspath(a)
|
|
114
|
+
if isfile(a):
|
|
115
|
+
self.email.Attachments.Add(a)
|
|
116
|
+
else:
|
|
117
|
+
try:
|
|
118
|
+
raise FileNotFoundError(f"file {a} could not be attached.")
|
|
119
|
+
except FileNotFoundError as e:
|
|
120
|
+
self._logger.error(e, exc_info=True)
|
|
121
|
+
raise e
|
|
122
|
+
else:
|
|
123
|
+
try:
|
|
124
|
+
raise FileNotFoundError(f"file {a} could not be attached.")
|
|
125
|
+
except FileNotFoundError as e:
|
|
126
|
+
self._logger.error(e, exc_info=True)
|
|
127
|
+
raise e
|
|
128
|
+
else:
|
|
129
|
+
try:
|
|
130
|
+
raise TypeError("attachments attribute must be a list")
|
|
131
|
+
except TypeError as e:
|
|
132
|
+
self._logger.error(e, exc_info=True)
|
|
133
|
+
raise e
|
|
134
|
+
else:
|
|
135
|
+
self._logger.debug("no attachments detected")
|
|
136
|
+
|
|
52
137
|
try:
|
|
53
138
|
# set the params
|
|
139
|
+
_validate_attachments()
|
|
54
140
|
self.email.To = recipient
|
|
55
141
|
self.email.Subject = subject
|
|
56
142
|
self.email.HtmlBody = text
|
|
@@ -146,18 +232,9 @@ if __name__ == "__main__":
|
|
|
146
232
|
r_dict = {
|
|
147
233
|
"subject": f"TEST: Your TEST "
|
|
148
234
|
f"agreement expires in 30 days or less!",
|
|
149
|
-
"text":
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
f"Please renew the aforementioned by dropping off a hard copy to "
|
|
153
|
-
f"the Albany Water Department at 10 N Enterprise Dr.<br>"
|
|
154
|
-
f"Thank You,<br>"
|
|
155
|
-
f"AWD"
|
|
156
|
-
f"<br>"
|
|
157
|
-
f"<br>"
|
|
158
|
-
f"<br>"
|
|
159
|
-
f"This is an automated email, Please do not respond directly to it.",
|
|
160
|
-
"recipient": ''
|
|
235
|
+
"text": "testing to see if the attachment works",
|
|
236
|
+
"recipient": 'pbehnke@albanyny.gov',
|
|
237
|
+
"attachments": []
|
|
161
238
|
}
|
|
162
239
|
#   is the tab character for emails
|
|
163
240
|
emailer.SetupEmail(**r_dict) # recipient="amcsparron@albanyny.gov", subject="test subject", text="test_body")
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: PyEmailerAJM
|
|
3
|
-
Version:
|
|
3
|
+
Version: 1.1
|
|
4
4
|
Summary: Allows for automating sending Email with the Outlook Desktop client. Future releases will add more client support
|
|
5
5
|
Home-page: https://github.com/amcsparron2793-Water/PyEmailer
|
|
6
6
|
Author: Amcsparron
|
|
7
7
|
Author-email: amcsparron@albanyny.gov
|
|
8
8
|
License: MIT License
|
|
9
|
-
Download-URL: https://github.com/amcsparron2793-Water/PyEmailer/archive/refs/tags/
|
|
9
|
+
Download-URL: https://github.com/amcsparron2793-Water/PyEmailer/archive/refs/tags/1.1.tar.gz
|
|
10
10
|
Keywords: Outlook,Email,Automation
|
|
11
11
|
Platform: UNKNOWN
|
|
12
12
|
License-File: LICENSE.txt
|
|
@@ -2,10 +2,10 @@ from setuptools import setup
|
|
|
2
2
|
|
|
3
3
|
setup(
|
|
4
4
|
name='PyEmailerAJM',
|
|
5
|
-
version='
|
|
5
|
+
version='1.1',
|
|
6
6
|
packages=['PyEmailerAJM'],
|
|
7
7
|
url='https://github.com/amcsparron2793-Water/PyEmailer',
|
|
8
|
-
download_url='https://github.com/amcsparron2793-Water/PyEmailer/archive/refs/tags/
|
|
8
|
+
download_url='https://github.com/amcsparron2793-Water/PyEmailer/archive/refs/tags/1.1.tar.gz',
|
|
9
9
|
keywords=["Outlook", "Email", "Automation"],
|
|
10
10
|
install_requires=['pywin32'],
|
|
11
11
|
license='MIT License',
|
PyEmailerAJM-0.1/README.md
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|