Skip to content

Instantly share code, notes, and snippets.

@ashafer01
Last active February 2, 2024 04:16
Show Gist options
  • Save ashafer01/1c1d8c551c3f4170c090f9d3bc68d61b to your computer and use it in GitHub Desktop.
Save ashafer01/1c1d8c551c3f4170c090f9d3bc68d61b to your computer and use it in GitHub Desktop.
Drop-in replacement for sendmail -t which relays to gmail smtp, should be easy to adapt to any smtp
#!/usr/bin/env python3
import email
import smtplib
import sys
smtp_address = "smtp.gmail.com"
smtp_port = 587
smtp_user_name = "[email protected]"
smtp_password = "YOUR_APP_PASSWORD"
with smtplib.SMTP(smtp_address, smtp_port) as smtp:
smtp.starttls()
smtp.login(smtp_user_name, smtp_password)
msg = email.message_from_string(sys.stdin.read())
smtp.send_message(msg, from_addr=smtp_user_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment