def sendemail(req, to, subject, msg, headers=None): """sendemail(Request, string, string, string, [dict]) -> None Send an email to the given person. If Reply-To is not in headers and there is a logged-in user, it defaults to the current user. """ from restrack.config import config msg = MIMEText(msg) msg['Subject'] = subject msg['From'] = config.EMAIL_FROM if req.user: msg['Reply-to'] = req.user msg['To'] = to if headers: msg.update(headers) if not config.SMTP_SERVER: return # Establish an SMTP object and connect to your mail server s = smtplib.SMTP() s.connect(config.SMTP_SERVER) if config.SMTP_USER: s.login(config.SMTP_USER, config.SMTP_PASSWORD) # Send the email - real from, real to, extra headers and content ... s.sendmail(msg['From'], msg['To'], msg.as_string()) s.quit()