Files
fultonbr 24ff9fd2fc On branch main
Initial commit

 Changes to be committed:
	new file:   README.md
	new file:   abx/apply_nsx_tags_for_tiers/README.md
	new file:   abx/apply_nsx_tags_for_tiers/action.py
	new file:   abx/list_vcenter_vms/README.md
	new file:   abx/list_vcenter_vms/action.py
	new file:   abx/send_email/README.md
	new file:   abx/send_email/action.py
	new file:   blueprints/forms/vdefend-form.json
	new file:   blueprints/vdefend-form-driven.yaml
2025-09-18 09:40:08 -05:00

35 lines
1.2 KiB
Python

import smtplib, ssl, os
from email.mime.text import MIMEText
def handler(context, inputs):
smtp_host = inputs.get("smtp_host") or os.getenv("SMTP_HOST")
smtp_port = int(inputs.get("smtp_port", 25))
smtp_user = inputs.get("smtp_user") or os.getenv("SMTP_USER")
smtp_pass = inputs.get("smtp_pass") or os.getenv("SMTP_PASS")
use_tls = bool(inputs.get("use_tls", False))
from_email = inputs["from_email"]
to_email = inputs["to_email"]
subject = inputs.get("subject", "vDefend policy created")
body = inputs.get("body", "")
msg = MIMEText(body, "plain", "utf-8")
msg["Subject"] = subject
msg["From"] = from_email
msg["To"] = to_email
if use_tls:
context = ssl.create_default_context()
with smtplib.SMTP(smtp_host, smtp_port) as server:
server.starttls(context=context)
if smtp_user and smtp_pass:
server.login(smtp_user, smtp_pass)
server.send_message(msg)
else:
with smtplib.SMTP(smtp_host, smtp_port) as server:
if smtp_user and smtp_pass:
server.login(smtp_user, smtp_pass)
server.send_message(msg)
return {"status": "sent", "to": to_email}