First cut of smtp connector

This commit is contained in:
Jon Herron 2023-06-29 14:14:39 -04:00
parent b1017a382b
commit 8215ed2cc3
6 changed files with 66 additions and 0 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
*~
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

7
poetry.lock generated Normal file
View File

@ -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"

15
pyproject.toml Normal file
View File

@ -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 <jon.herron@yahoo.com>"]
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"

View File

View File

View File

@ -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",
}