# # Replacement for sendmail utility that uses SMTP protocol for delivery. # By default, sendmail reads message body from stdin and delivers it to # address(es) passed on the commandline. # http://www.feep.net/sendmail/tutorial/run/commandline.html # # Various sendmail options are not supported, because the script was # developed as a simple way to send mails from console tools like Darcs # through GMail. # # With Darcs 1.x.x on windows use: # darcs send -v --sendmail-command="c:\path\to\python sendmail.py """%t""" %<" # or from batch file: # darcs send -v --sendmail-command="c:\path\to\python sendmail.py """%%t""" %%<" # # techtonik // php.net 2008-03-30 # --*- Configuration -*-- # MAILSERV = "smtp.gmail.com" # Secure TLS connections are required by GMail SECURE = 1 SMTPDEBUG = 0 # #: Unset login to skip authentication LOGIN="example@gmail.com" #: If pass is None it will be asked PASS=None # --*- Parameters -*-- # FROM = "anything@example.com" TO = "anything@example.com" import sys import smtplib from getpass import getpass def sendmail(sndr, rcpt, body): # Even though To: and Cc: headers are present in the message, SMTP # protocol still requires that all recepient addresses are passed # to server explicitly server = smtplib.SMTP() if SMTPDEBUG: server.set_debuglevel(1) server.connect(MAILSERV) if SECURE: server.ehlo() server.starttls() server.ehlo() if LOGIN != None: if PASS == None: pswd = getpass() else: pswd = PASS server.login(LOGIN, pswd) server.sendmail(sndr, rcpt, body) server.quit() if __name__ == "__main__": if len(sys.argv) > 1: to = sys.argv[1:] else: to = TO mailbody = sys.stdin.read() sendmail(FROM, to, mailbody)