-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
88 lines (65 loc) · 2.4 KB
/
script.py
File metadata and controls
88 lines (65 loc) · 2.4 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
import smtplib
import os
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
import json
import time
# The mail addresses and password
sender_address = ''
sender_pass = ''
# Setup the MIME
# fetch email into this dynamic list
r = open("src/New_folder/csvjson.json",)
# r = open("src/New_folder/main.json",)
reciepents = json.load(r)
r.close()
lst = open(r"lst.json")
# starting session
session = smtplib.SMTP('smtp.mail.yahoo.com', 587)
# starting secure login
session.starttls()
# logging in
session.login(sender_address, sender_pass)
# this function sends the email
def sendmail(sender_address, receiver_address, subject, content, receiver_name, receiver_id):
message = MIMEMultipart()
message['From'] = sender_address
message['To'] = receiver_address
# The subject line
message['Subject'] = subject
# The body and the attachments for the mail
message.attach(MIMEText(content, 'plain'))
attach_file_name = 'src/New_folder/certificates/' + str(i+1)+'.png'
with open(attach_file_name, 'rb') as f:
img_data = f.read()
image = MIMEImage(img_data, name=os.path.basename(attach_file_name))
message.attach(image)
print("image attached! with name: " + str(i+1))
text = message.as_string()
session.sendmail(sender_address, receiver_address, text)
print(f"Mail Sent to {receiver_name} + " + str(i))
subject = "Hack-for-change certificates ✨"
def func_content_final(content):
greeting = "Hello " + reciever_name + ",\n"
signature = "\n\nThank you \nHack for Change"
content_ = greeting + content + signature
return content_
def making_listToJson():
res = []
for i in range(1,69):
temp = {"name": reciever_name[i+1],
"email": sender_address[i]}
res.append(temp)
print(res)
jsonFile = open("lst.json", "w")
jsonFile.write(json.dumps(res))
jsonFile.close()
# for sending mails in a loop
for i in range(166, 167):
content = '''PFA copy of your E-certificate for The hackathon: Hack-For-change.'''
reciever_name = reciepents[i]["name"]
content_final = func_content_final(content)
sendmail(sender_address, reciepents[i]["email"],
subject, content_final, reciever_name, i+1)
print(f'sent to {reciepents[i+1]["name"]}')