-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
62 lines (47 loc) · 1.85 KB
/
main.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
from flask import Flask,render_template,request
from PIL import Image as a1
from PIL import ImageDraw as a2
from PIL import ImageFont as a3
import imghdr
import smtplib
from email.message import EmailMessage
app = Flask(__name__)
codes = ["A","B","C","D","E","F","G","H","I","J","K","L"]
winners =12
@app.route("/")
def Index():
return render_template("index.html")
@app.route("/form" , methods=["POST"])
def form():
# Enter your email and password from which you want to sent the image
Your_email = "dummy e-mail"
Your_Password = "dummy password"
email = request.form.get("email")
name = request.form.get("name")
code = request.form.get("code")
font = a3.truetype('arial.ttf', 65)
for i in range(0,winners):
if(code == codes[i]):
codes[i] = ran.randint(8485,904356)
ay1 = a1.open('sample_cert.jpg')
draw = a2.Draw(ay1)
draw.text(xy=(401, 234), text='{}'.format(name), fill=(0, 0, 0), font=font)
ay1.save('cert_save_folder/{}.jpg'.format(name))
newMessage = EmailMessage()
newMessage['Subject'] = "Check out the new logo"
newMessage['From'] = Your_email
newMessage['To'] = email
newMessage.set_content('Let me know what you think. Image attached!')
with open('cert_save_folder/{}.jpg'.format(name), 'rb') as f:
image_data = f.read()
image_type = imghdr.what(f.name)
image_name = f.name
newMessage.add_attachment(image_data, maintype='image', subtype=image_type, filename=image_name)
server = smtplib.SMTP("smtp.gmail.com" , 587)
server.starttls()
server.login(Your_email , Your_Password)
server.send_message(newMessage)
return render_template("result.html")
return render_template("index.html")
if __name__ == "__main__":
app.run(debug=True)