-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend_email.py
26 lines (23 loc) · 880 Bytes
/
send_email.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
import smtplib
from email.mime.text import MIMEText
# Function to send an email
def send_email(subject, body, to_email, from_email, smtp_server, smtp_port, login, password):
msg = MIMEText(body) # Create email body
msg["Subject"] = subject # Add subject
msg["From"] = from_email # Sender
msg["To"] = to_email # Recipient
with smtplib.SMTP(smtp_server, smtp_port) as server: # Connect to SMTP server
server.starttls() # Secure the connection
server.login(login, password) # Login to the server
server.send_message(msg) # Send email
# Example usage
send_email(
subject="Test Email",
body="Hello! This is a test email.",
to_email="[email protected]",
from_email="[email protected]",
smtp_server="smtp.gmail.com",
smtp_port=587,
login="[email protected]",
password="your_password"
)