import smtplib
from email.mime.text import MIMEText
def send_email(recipient, subject, body):
# SMTP server settings
smtp_server = 'smtp.example.com'
smtp_port = 587
smtp_user = 'your_email@example.com'
smtp_password = 'your_password'
# Create the email message
msg = MIMEText(body)
msg['Subject'] = subject
msg['From'] = smtp_user
msg['To'] = recipient
# Connect to the SMTP server
server = smtplib.SMTP(smtp_server, smtp_port)
server.starttls()
server.login(smtp_user, smtp_password)
# Send the email
server.sendmail(smtp_user, recipient, msg.as_string())
# Close the connection
server.quit()
# Example usage
recipient = 'recipient@example.com'
subject = 'Test email from Raspberry Pi'
body = 'Hello, this is a test email sent from a Raspberry Pi.'
send_email(recipient, subject, body)
from email.mime.text import MIMEText
def send_email(recipient, subject, body):
# SMTP server settings
smtp_server = 'smtp.example.com'
smtp_port = 587
smtp_user = 'your_email@example.com'
smtp_password = 'your_password'
# Create the email message
msg = MIMEText(body)
msg['Subject'] = subject
msg['From'] = smtp_user
msg['To'] = recipient
# Connect to the SMTP server
server = smtplib.SMTP(smtp_server, smtp_port)
server.starttls()
server.login(smtp_user, smtp_password)
# Send the email
server.sendmail(smtp_user, recipient, msg.as_string())
# Close the connection
server.quit()
# Example usage
recipient = 'recipient@example.com'
subject = 'Test email from Raspberry Pi'
body = 'Hello, this is a test email sent from a Raspberry Pi.'
send_email(recipient, subject, body)