-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathai_safety_email.py
More file actions
32 lines (26 loc) · 951 Bytes
/
ai_safety_email.py
File metadata and controls
32 lines (26 loc) · 951 Bytes
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
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import json
from pathlib import Path
def send_email(receiver_email: str,
subject: str,
content: MIMEText,
config_path: Path=Path(__file__).parent / ".env") -> None:
conf = None # TODO: Make this a typedDict
with open(config_path, "r") as f:
conf = json.loads(f.read())
sender_email = conf["sender_email"]
password = conf["password"]
host = conf["host"]
port = conf["port"]
msg = MIMEMultipart()
msg['From'] = sender_email
msg['To'] = receiver_email
msg['Subject'] = subject
msg.attach(content)
with smtplib.SMTP(host, port) as server:
server.starttls()
server.login(sender_email, password)
server.sendmail(sender_email, receiver_email, msg.as_string())
print(f"Email sent successfully to {receiver_email}.")