Created
May 23, 2016 19:39
-
-
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...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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