Skip to content

Instantly share code, notes, and snippets.

@zombified
Created May 23, 2016 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zombified/c93c6cd299643cc67d97fd9b5bd63f67 to your computer and use it in GitHub Desktop.
Save zombified/c93c6cd299643cc67d97fd9b5bd63f67 to your computer and use it in GitHub Desktop.
for the times when you just want to send an email and you don't want to setup postfix because you don't care about the email all that much...
#!/usr/bin/env python
import argparse
from email import message_from_string
import smtplib
import sys
def justsend():
parser = argparse.ArgumentParser(description="Just send and email message to a SMTP server.") # noqa
parser.add_argument("-a", "--address", action="store", dest="address", type=str, # noqa
help="host:port of SMTP server to send email to",
default="127.0.0.1")
args = parser.parse_args()
msg = message_from_string(sys.stdin.read())
s = smtplib.SMTP(args.address)
to = None
if isinstance(msg['To'], list):
to = msg['To']
else:
to = [msg['To']]
s.sendmail(msg['From'], to, msg.as_string())
s.quit()
if __name__ == '__main__':
justsend()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment