Skip to content

Instantly share code, notes, and snippets.

@Nilpo
Forked from ashafer01/mail_relay.py
Created February 2, 2024 04:16
Show Gist options
  • Save Nilpo/f7c8c5dbbc69ec1eba6e1864e7f44675 to your computer and use it in GitHub Desktop.
Save Nilpo/f7c8c5dbbc69ec1eba6e1864e7f44675 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