-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsendmail.py
117 lines (90 loc) · 3.67 KB
/
sendmail.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
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
107
108
109
110
111
112
113
114
115
116
117
# Imports
import os
import random
import smtplib
import sqlite3
from models.users import add_code
def send_mail(path: str, email: str) -> None:
"""Sends mail for resetting password to the user
Args:
path: Database path
email: User email id
Returns:
None
"""
MAILGUN_EMAIL = os.getenv("MAILGUN_EMAIL")
MAILGUN_PWD = os.getenv("MAILGUN_PWD")
try:
server = smtplib.SMTP("smtp.mailgun.org", 587)
server.login(MAILGUN_EMAIL, MAILGUN_PWD)
except:
print("Error Connecting To Mail Server")
key = random.randint(1000, 9999)
add_code(path, key, email)
url = "http://localhost:8000/reset"
subject = "RESET YOUR PASSWORD:"
body = f'Dear User\nPlease Click on the Link Below to Reset your "Code"Vid19 Password for your {email} account.\n\nThis is your 4 Digit Verification Code: {key} \n\nLink: {url} \n\nIf you didnt ask to reset your password please IGNORE this email!\n\nThank you\nWarm Regards\nTeam "Code"Vid19'
msg = f"Subject: {subject}\n\n{body}"
try:
server.sendmail(MAILGUN_EMAIL, email, msg)
except:
print("Error Sending Mail")
server.quit()
def send_buy(path: str, data: tuple) -> None:
"""Sends a mail to the user when the user buys stock
Args:
path: Database path
data: Tuple with all transaction data
symbol = data[0]
price = data[1]
quant = data[2]
total = data[3]
email = data[4]
date = data[5]
Returns:
None
"""
MAILGUN_EMAIL = os.getenv("MAILGUN_EMAIL")
MAILGUN_PWD = os.getenv("MAILGUN_PWD")
try:
server = smtplib.SMTP("smtp.mailgun.org", 587)
server.login(MAILGUN_EMAIL, MAILGUN_PWD)
except:
print("Error Connecting To Mail Server")
subject = "Stock Transaction Receipt: IMP!"
body = f'Dear User\nHere is your transaction receipt for your {data[4]} account.\n\nYou purchased {data[2]} units of the {data[0]} stock on {data[5]} at a rate of $ {data[1]} per stock unit.\n\nYour total expenditure was $ {data[3]}. Thank you for using "Code"vid19 Solutions.\n\nIf you did not make or authorize this transaction PLEASE CONTACT US IMMEDIATELY!\n\nThank you\nWarm Regards\nTeam "Code"Vid19'
msg = f"Subject: {subject}\n\n{body}"
try:
server.sendmail(MAILGUN_EMAIL, data[4], msg)
except:
print("Error Sending Mail")
server.quit()
def send_sell(path: str, data: tuple) -> None:
"""Sends a mail to the user when the user sells stock
Args:
path: Database path
data: Tuple with all transaction data
symbol = data[0]
price = data[1]
quant = data[2]
total = data[3]
email = data[4]
date = data[5]
Returns:
None
"""
MAILGUN_EMAIL = os.getenv("MAILGUN_EMAIL")
MAILGUN_PWD = os.getenv("MAILGUN_PWD")
try:
server = smtplib.SMTP("smtp.mailgun.org", 587)
server.login(MAILGUN_EMAIL, MAILGUN_PWD)
except:
print("Error Connecting To Mail Server")
subject = "Stock Transaction Receipt: IMP!"
body = f'Dear User\nHere is your transaction receipt for your {data[4]} account.\n\nYou sold {data[2]} units of the {data[0]} stock on {data[5]} at a rate of $ {data[1]} per stock unit.\n\nYour total earning was $ {data[3]}. Thank you for using "Code"vid19 Solutions.\n\nIf you did not make or authorize this transaction PLEASE CONTACT US IMMEDIATELY!\n\nThank you\nWarm Regards\nTeam "Code"Vid19'
msg = f"Subject: {subject}\n\n{body}"
try:
server.sendmail(MAILGUN_EMAIL, data[4], msg)
except:
print("Error Sending Mail")
server.quit()