diff --git a/.gitignore b/.gitignore index 68bc17f..ba1b4ac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +*~ + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/poetry.lock b/poetry.lock new file mode 100644 index 0000000..5060a87 --- /dev/null +++ b/poetry.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Poetry 1.4.2 and should not be changed by hand. +package = [] + +[metadata] +lock-version = "2.0" +python-versions = "^3.9" +content-hash = "c595a0588c25d58f3e3834ad7169126836d262b925fe6ca9b5d540dcf301d254" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..1811cc4 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,15 @@ +[tool.poetry] +name = "connector-smtp" +version = "0.1.0" +description = "Make SMTP Requests available to SpiffWorkflow Service Tasks" +authors = ["Jon Herron "] +readme = "README.md" +packages = [{include = "connector_smtp", from = "src" }] + +[tool.poetry.dependencies] +python = "^3.9" + + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" diff --git a/src/connector_smtp/__init__.py b/src/connector_smtp/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/connector_smtp/commands/__init__.py b/src/connector_smtp/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/connector_smtp/commands/sendEmail.py b/src/connector_smtp/commands/sendEmail.py new file mode 100644 index 0000000..ce5f357 --- /dev/null +++ b/src/connector_smtp/commands/sendEmail.py @@ -0,0 +1,42 @@ +import json + +from email.message import EmailMessage +from smtplib import SMTP + +class SendEmail: + def __init__(self, + smtp_host: str, + smtp_port: int, + email_subject: str, + email_body: str, + email_to: str, + email_from: str, + ): + self.smtp_host = smtp_host + self.smtp_port = smtp_port + self.email_subject = email_subject + self.email_body = email_body + self.email_to = email_to + self.email_from = email_from + + def execute(self, config, task_data): + message = EmailMessage() + message.set_content(self.email_body) + message["Subject"] = self.email_subject + message["From"] = self.email_from + message["To"] = self.email_to + + response = {} + + try: + with SMTP(self.smtp_host, self.smtp_port) as smtp: + smtp.send_message(message) + except Exception as e: + response["error"] = str(e) + + return { + "response": json.dumps(response), + "status": 200, + "mimetype": "application/json", + } +