-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail.py
46 lines (33 loc) · 1.16 KB
/
mail.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
import re
import smtplib
import ssl
import variables
def mail_check(mail):
pattern = "([A-Za-z0-9]+[.-_])*[A-Za-z0-9]+@[A-Za-z0-9-]+(\\.[A-Z|a-z]{2,})+"
return re.match(pattern, mail) is not None
def email_validity():
sender_boolean = mail_check(variables.sender_email)
receiver_boolean = mail_check(variables.receiver_email)
if not sender_boolean and not receiver_boolean:
print("Sender email and receiver email are incorrect.")
elif not sender_boolean:
print("Sender email is incorrect.")
elif not receiver_boolean:
print("Receiver email is incorrect.")
else:
return True
def password_validity():
if variables.password == "":
print("You don't have a password.")
else:
return True
def send_mail(message):
context = ssl.create_default_context()
with smtplib.SMTP_SSL(
variables.smtp_server, variables.port, context=context
) as server:
server.login(variables.sender_email, variables.password)
server.sendmail(variables.sender_email, variables.receiver_email, message)
email_check = email_validity()
password_check = password_validity()
send_check = False