Skip to content

Instantly share code, notes, and snippets.

Created November 11, 2013 23:08
What would you like to do?
A short mailx style script with smtp support
#!/usr/bin/env python
# - mailx style tool with SMTP support
import smtplib
from optparse import OptionParser
import sys
from email.mime.text import MIMEText
def send_mail():
parser = OptionParser()
parser.add_option("-t", help="to", action="store", dest="to")
parser.add_option("-f", help="from", action="store", dest="fromad")
parser.add_option("-s", help="subject", action="store", dest="subject")
parser.add_option("-x", help="SMTP server", action="store", dest="server",
(options, args) = parser.parse_args()
msg = MIMEText(
msg['Subject'] = options.subject
msg['From'] = options.fromad
msg['To'] =
s = smtplib.SMTP(options.server)
s.sendmail(options.fromad, [], msg.as_string())
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment