-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp3.py
79 lines (62 loc) · 2.46 KB
/
app3.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
from fileinput import filename
from PyPDF2 import PdfFileWriter, PdfFileReader
import io
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
import pandas as pd
import smtplib
from email.utils import formataddr
from email.message import EmailMessage
import ssl
from email.utils import make_msgid
def generatePDF(text):
packet = io.BytesIO()
can = canvas.Canvas(packet, pagesize=letter)
can.drawString(380, 560, text)
can.save()
#move to the beginning of the StringIO buffer
packet.seek(0)
# create a new PDF with Reportlab
new_pdf = PdfFileReader(packet)
# read your existing PDF
existing_pdf = PdfFileReader(open("promax.pdf", "rb"))
output = PdfFileWriter()
# add the "watermark" (which is the new pdf) on the existing page
page = existing_pdf.getPage(0)
page.mergePage(new_pdf.getPage(0))
output.addPage(page)
# finally, write "output" to a real file
outputStream = open(f"{text}.pdf", "wb")
output.write(outputStream)
outputStream.close()
df = pd.read_csv('credentials.csv', sep=',', header=None)
print(df.values[0])
context=ssl._create_unverified_context()
for ite in df.values :
name_full = ite[1]+" "+ite[2]
generatePDF( text=name_full)
with smtplib.SMTP_SSL(host="smtp.123-reg.co.uk" , port="465" ,context=context )as server:
server.login("[email protected]", "xLYpXuKG_Bwj27n")
# server.verify('[email protected]')
msg = EmailMessage()
msg.set_content(f'''
Ci-joints vos accès à votre compte sur la plateforme Turing Jobs :
lien : https://www.turingjobs.net
Email :{ite[1]}
Mot de passe :{ite[2]}
''')
msg['Subject'] = "Vos accès à la platforme Turing Jobs"
msg['From'] = formataddr(('Turing Jobs' , "[email protected]"))
msg['To'] = ite[0]
msg['message-id'] = make_msgid()
# with open(f"{name_full}.pdf", 'rb') as fp:
# file_data = fp.read()
# msg.add_attachment(file_data , maintype="application" , subtype="pdf" , filename="proforma.pdf" )
try :
server.send_message(msg)
except Exception as e :
print('--------------error sending email')
print('--------------name' , name_full)
print('--------------error message ', e)
print('***************************************************' )
server.quit()