Created
May 21, 2013 14:26
-
-
Save ctaloi/5620193 to your computer and use it in GitHub Desktop.
Quick Python to sendmail script
This file contains hidden or 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 os | |
import argparse | |
def buildEmail(): | |
parser = argparse.ArgumentParser(add_help=True) | |
parser.add_argument('em_subject', help='Email Subject Line') | |
parser.add_argument('em_body', help='Body of Email') | |
parser.add_argument('em_to', help='Email Recipient') | |
parser.add_argument('em_from', help='Email Sender') | |
args = parser.parse_args() | |
sendMail(args.em_from, args.em_to, args.em_subject, args.em_body) | |
def sendMail(em_from, em_to, em_subject, em_body): | |
sendmail_location = '/usr/sbin/sendmail' | |
p = os.popen('%s -t' % sendmail_location, 'w') | |
p.write('From: %s\n' % em_from) | |
p.write('To: %s\n' % em_to) | |
p.write('Subject: %s \n' % em_subject) | |
p.write('\n') | |
p.write(em_body) | |
p.close() | |
def main(): | |
buildEmail() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment