-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmsg.py
More file actions
21 lines (17 loc) · 661 Bytes
/
msg.py
File metadata and controls
21 lines (17 loc) · 661 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
# Set up the SMTP server
smtp_server = "smtp.gmail.com" # e.g., smtp.gmail.com for Gmail
def send_email(from_email, to_email, body, key):
# Create a MIMEMultipart object
msg = MIMEMultipart()
msg['From'] = from_email
msg['To'] = to_email
# Attach the email body to the message
msg.attach(MIMEText(body, 'plain'))
server = smtplib.SMTP(smtp_server, 587) # Port 587 for TLS
server.starttls() # Secure the connection
server.login(from_email, key)
text = msg.as_string()
server.sendmail(from_email, to_email, text)