def send_mail(fromaddr, recipients, message, secure=False): with smtpd_context() as client: try: client.ehlo() if secure: logbook.debug("Starting TLS...") client.starttls() logbook.debug("TLS initiated") client.sendmail(fromaddr, recipients, message) except: logbook.error("Error while sending email", exc_info=True) client.close() raise
def _get_smtpd_context(self): if self._args.smtp_port is None: with smtpd_context() as result: yield result else: yield SMTP("127.0.0.1", self._args.smtp_port)