-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPFE_Bot.py
More file actions
106 lines (101 loc) · 4.53 KB
/
PFE_Bot.py
File metadata and controls
106 lines (101 loc) · 4.53 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
from tkinter import filedialog
import os
import win32com.client
import comtypes.client
from email.message import EmailMessage
import mimetypes
import smtplib
print('''
██████ ███████ ███████ ██████ ██████ ████████
██ ██ ██ ██ ██ ██ ██ ██ ██
██████ █████ █████ ██████ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██
██ ██ ███████ ██████ ██████ ██
Created with love By TNLegend
''')
answer = int(input("Type 1 to import your resume and follow up letter\nType 2 to exit\n>>"))
if answer == 2:
exit(0)
else:
# preparing cv and resume file
path = str(filedialog.askopenfilename(title="select your cv and resume", filetypes=[("doc file", ".doc*")]))
path = path.replace("/", "\\")
print(path)
toReplace = input("please type the text you want to replace >>")
wd_replace = 2 # 2=replace all occurences, 1=replace one occurence, 0=replace no occurences
wd_find_wrap = 1 # 2=ask to continue, 1=continue search, 0=end if search range is reached
path2 = str(filedialog.askopenfilename(title="select emails list", filetypes=[("text file", ".txt")]))
print(path2)
sender = input("type your email >>")
mailDomain = sender[sender.rfind("@")+1:]
with open("smtps.txt",mode="r",encoding="utf-8") as smtps:
lines = smtps.readlines()
mySmtp = ""
for line in lines:
if mailDomain == line.split(":")[0]:
mySmtp = line.split(":")[1].strip()
print(f"Found smtp : {mySmtp}")
if mySmtp == "":
print("Email not supported by the Bot")
exit(0)
print(f"Your mail domain : {mailDomain}")
print(f"Found smtp : {mySmtp}")
if (mailDomain == "gmail.com") or (mailDomain == "icloud.com"):
appPass = input("type your generated appPassword >>")
else:
appPass = input("type your email password >>")
subject = input("type email subject >>")
body = input("type what you want to send in all mails body >>")
with open(path2, mode="r", encoding="utf-8") as mails:
lines = mails.readlines()
for line in lines:
myList = line.split(":")
receiver = myList[0].strip()
replaced = myList[1].strip()
# Open Word
word_app = win32com.client.DispatchEx("Word.Application")
word_app.Visible = False
word_app.DisplayAlerts = False
word_app.Documents.Open(fr"{path}")
# API documentation: https://learn.microsoft.com/en-us/office/vba/api/word.find.execute
word_app.Selection.Find.Execute(
FindText=toReplace,
ReplaceWith=replaced,
Replace=wd_replace,
Forward=True,
MatchCase=True,
MatchWholeWord=False,
MatchWildcards=True,
MatchSoundsLike=False,
MatchAllWordForms=False,
Wrap=wd_find_wrap,
Format=True,
)
# Save the new file
word_app.ActiveDocument.SaveAs(str(f"{os.getcwd()}/final.docx"))
word_app.ActiveDocument.Close(SaveChanges=False)
word = comtypes.client.CreateObject('Word.Application')
word.Quit()
word_app.Application.Quit()
word = comtypes.client.CreateObject('Word.Application')
doc = word.Documents.Open(str(f"{os.getcwd()}/final.docx"))
wdFormatPDF = 17
doc.SaveAs(str(f"{os.getcwd()}/final.pdf"), FileFormat=wdFormatPDF)
doc.Close()
os.remove(f"{os.getcwd()}/final.docx")
message = EmailMessage()
message['from'] = sender
message['to'] = receiver
message['subject'] = subject
message.set_content(body)
mime_type, _ = mimetypes.guess_type(f"{os.getcwd()}/final.pdf")
mime_type, mime_subtype = mime_type.split('/', 1)
with open("final.pdf", 'rb') as ap:
message.add_attachment(ap.read(), maintype=mime_type, subtype=mime_subtype,
filename=os.path.basename(f"{os.getcwd()}/final.pdf"))
with smtplib.SMTP(host=mySmtp, port=587) as smtp:
smtp.ehlo() # start communiction with smtp server
smtp.starttls() # tls = transport layer security
smtp.login(sender, appPass)
smtp.send_message(message)
print(f"email sent to {receiver}")