Skip to content

Instantly share code, notes, and snippets.

@rdlmda
Created January 17, 2025 15:05
Show Gist options
  • Save rdlmda/7a34cb61678a3c819f7ecdf2a389518f to your computer and use it in GitHub Desktop.
Save rdlmda/7a34cb61678a3c819f7ecdf2a389518f to your computer and use it in GitHub Desktop.
barebones SMTP email delivery with Python
import smtplib
from email.mime.text import MIMEText
smtp_server = 'mail.domain.com'
smtp_port = 587 # Typically 587 for TLS
username = '[email protected]'
from_email = username
password = 'password'
to_email = 'recipient'
subject = 'Test Email'
body = 'This is a test email sent from Python!'
# Create the email
msg = MIMEText(body)
msg['Subject'] = subject
msg['From'] = from_email
msg['To'] = to_email
# Send the email
with smtplib.SMTP(smtp_server, smtp_port) as server:
server.starttls() # Upgrade the connection to a secure encrypted SSL/TLS connection
server.login(username, password)
server.sendmail(from_email, to_email, msg.as_string())
print("Email sent successfully!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment