Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.