def emailResult(body, subject): fromAddress = toAddress = '*****@*****.**' msg = email.mime.text.MIMEText(body) msg["From"] = fromAddress msg["To"] = toAddress msg["Subject"] = subject message = msg.as_string() if USE_SMTP: if False: s = smtplib.SMTP('localhost') else: import localpass s = smtplib.SMTP(localpass.SMTP_SERVER, port=localpass.SMTP_PORT) s.ehlo(fromAddress) s.starttls() s.ehlo(fromAddress) localpass.smtplogin(s) print 'sending mail...' s.sendmail(fromAddress, (toAddress,), message) print 'quitting smtp...' s.quit() else: p = subprocess.Popen(["/usr/sbin/sendmail", "-t"], stdin=subprocess.PIPE) p.communicate(message)
def sendEmail(toEmailAddr, subject, messageText): try: import localpass useSendMail = False except ImportError: useSendMail = True if not useSendMail: SMTP_SERVER = localpass.SMTP_SERVER SMTP_PORT = localpass.SMTP_PORT FROM_EMAIL = '*****@*****.**' smtp = smtplib.SMTP(SMTP_SERVER, port=SMTP_PORT) smtp.ehlo(FROM_EMAIL) smtp.starttls() smtp.ehlo(FROM_EMAIL) localpass.smtplogin(smtp) msg = 'From: %s\r\n' % '*****@*****.**' msg += 'To: %s\r\n' % toEmailAddr msg += 'Subject: %s\r\n' % subject msg += '\r\n' smtp.sendmail('*****@*****.**', toEmailAddr.split(','), msg) smtp.quit() else: from email.mime.text import MIMEText from subprocess import Popen, PIPE msg = MIMEText(messageText) msg["From"] = '*****@*****.**' msg["To"] = toEmailAddr msg["Subject"] = subject p = Popen(["/usr/sbin/sendmail", "-t"], stdin=PIPE) p.communicate(msg.as_string())
def sendEmail(emailAddress, message): if localpass is None: print 'WARNING: no smtp password; skipping email' return SMTP_SERVER = localpass.SMTP_SERVER SMTP_PORT = localpass.SMTP_PORT FROM_EMAIL = '*****@*****.**' smtp = smtplib.SMTP(SMTP_SERVER, port=SMTP_PORT) smtp.ehlo(FROM_EMAIL) smtp.starttls() smtp.ehlo(FROM_EMAIL) localpass.smtplogin(smtp) smtp.sendmail(FROM_EMAIL, emailAddress.split(','), message) smtp.quit()