-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_1.py
53 lines (44 loc) · 1.44 KB
/
example_1.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
from etext2.SMS_handler import EmailHandler
import logging, shutil, os
"""
Text sender/receiver using smtplib and imaplib
Dependencies:
- fast_mail_parser (https://pypi.org/project/fast-mail-parser/)
Instructions for running:
- Change Set EMAIL below
- Set PASS as an environmental variable
- Run the code
- Text your email (e.g. send "testing" to [email protected])
- Your phone should get a text in return with the content in uppercase
"""
EMAIL = "[email protected]"
try:
PASS = os.environ["PASS"]
except:
raise Exception("Please set PASS as an environmental variable!")
def clear(folder):
for filename in os.listdir(folder):
file_path = os.path.join(folder, filename)
try:
if os.path.isfile(file_path) or os.path.islink(file_path):
os.unlink(file_path)
elif os.path.isdir(file_path):
shutil.rmtree(file_path)
except Exception as e:
print('Failed to delete %s. Reason: %s' % (file_path, e))
def main():
handler = EmailHandler(EMAIL, PASS, loglevel=logging.DEBUG)
@handler.on_message
def on_message(message):
print("New message: " + str(message))
clear("saved_files")
if message.has_attachment:
message.download_attachments("saved_files")
handler.send_message(
message.number,
message.body[:100].upper(),
subject="response in uppercase",
files=["saved_files/" + file for file in os.listdir("saved_files")])
handler.run()
if __name__ == "__main__":
main()