-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheMail.py
More file actions
46 lines (36 loc) · 1.23 KB
/
eMail.py
File metadata and controls
46 lines (36 loc) · 1.23 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
from email.message import EmailMessage
import ssl
import smtplib
from sshhhh import EMAIL_ADDRESS, EMAIL_PASSWORD
from validate_email import validate_email
def isValid(email: str) -> bool:
"""
Validates whether the given email address is valid or not.
"""
return validate_email(email_address=email)
def send_email(receiver, subject, body) -> bool:
"""
Sends an email message.
Returns:
Parameters:
receiver (str): The email address of the recipient.
subject (str): The subject of the email.
body (str): The body content of the email.
bool: True if the email is sent successfully, False otherwise.
"""
# email_sender = EMAIL_ADDRESS
# email_password = EMAIL_PASSWORD
# email_receiver = receiver
em = EmailMessage()
em["From"] = EMAIL_ADDRESS
em['To'] = receiver
em['Subject'] = subject
em.set_content(body)
context = ssl.create_default_context()
try:
with smtplib.SMTP_SSL('smtp.gmail.com', 465, context=context) as smtp:
smtp.login(EMAIL_ADDRESS, EMAIL_PASSWORD)
smtp.sendmail(EMAIL_ADDRESS, receiver, em.as_string())
return True
except:
return False