def main(): if bulk_mode: content_txt = "" parameters, contexts = utils.read_bulk_contexts() hosts = set() for context in contexts: context.update(parameters) content_txt += construct_content(context) mailto = context["CONTACTEMAIL"] # Assume the same in each context subject = context["SUBJECT"] hosts.add(context["HOSTNAME"]) # Use the single context subject in case there is only one context in the bulk if len(contexts) > 1: subject = utils.get_bulk_notification_subject(contexts, hosts) else: # gather all options from env context = utils.collect_context() content_txt = construct_content(context) mailto = context["CONTACTEMAIL"] subject = context["SUBJECT"] if not mailto: # e.g. empty field in user database sys.stdout.write( "Cannot send ASCII email: empty destination email address\n") sys.exit(2) # Create the mail and send it from_address = utils.format_address( context.get("PARAMETER_FROM_DISPLAY_NAME", ""), context.get("PARAMETER_FROM_ADDRESS", utils.default_from_address()), ) reply_to = utils.format_address( context.get("PARAMETER_REPLY_TO_DISPLAY_NAME", ""), context.get("PARAMETER_REPLY_TO_ADDRESS", ""), ) m = utils.set_mail_headers( mailto, subject, from_address, reply_to, MIMEText(content_txt, "plain", _charset="utf-8")) try: sys.exit(utils.send_mail_sendmail(m, mailto, from_address)) except Exception as e: sys.stderr.write("Unhandled exception: %s\n" % e) # unhandled exception, don't retry this... sys.exit(2)
def send_mail(message, target, from_address, context): if "PARAMETER_SMTP_PORT" in context: return send_mail_smtp(message, target, from_address, context) return utils.send_mail_sendmail(message, target, from_address)
def send_mail(message: Message, target: str, from_address: str, context: dict[str, str]) -> int: if "PARAMETER_SMTP_PORT" in context: return send_mail_smtp(message, target, from_address, context) return utils.send_mail_sendmail(message, target, from_address)