-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemail_sender.py
More file actions
42 lines (32 loc) · 1.12 KB
/
email_sender.py
File metadata and controls
42 lines (32 loc) · 1.12 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
import smtplib, ssl
SENDER, PASSWORD = "balouka.reminder@gmail.com", "Reminder1234"
template = """\
Subject: #Title#
#Body#
#Sign#
"""
def send_email(receiver: str, title: str, body: str, sign: str) -> bool:
"""
Sends an email to a given email address
:param receiver: The email of the receiver wanted
:param message: The message to send
:return: True if email was sent successful and False if it had failed
"""
port = 465
context = ssl.create_default_context()
print("Starting to send")
message = template.replace("#Title#", title)
message = message.replace("#Body#", body)
message = message.replace("#Sign#", sign)
try:
with smtplib.SMTP_SSL("smtp.gmail.com", port,
context=context) as server:
server.login(SENDER, PASSWORD)
server.sendmail(SENDER, receiver, message)
print("email was sent!")
except Exception as e:
print("email was not sent do to an error:\n", e)
return False
return True
if __name__ == '__main__':
send_email("nirblo50@gmail.com", "message from site", "132", "nir")