Skip to content

Commit 8ca07f7

Browse files
authored
Feat/email destination changes (#121)
* Adjust schema for email destinations to make startTLS and credentials optional, and require smtp server and sender to be set * Remove defaults from email destination schema and set in TaskHandler * Adjust test email protocol schema * Fix dictionary key check for smtp credentials * bump version v25.3.0 -> v25.3.1
1 parent 41358b1 commit 8ca07f7

File tree

6 files changed

+41
-13
lines changed

6 files changed

+41
-13
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
#v25.3.1
4+
5+
- Adjust email_destination TaskHandler to allow use of TLS/credentials to be optional, and set default port to 587
6+
- Adjust email_destination protocol schema to ensure that smtp_server and sender are set
7+
38
# v25.3.0
49

510
- Add ignore_errors=True to problematic .gnupg removal

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "opentaskpy"
7-
version = "v25.3.0"
7+
version = "v25.3.1"
88
authors = [{ name = "Adam McDonagh", email = "adam@elitemonkey.net" }]
99
license = { text = "GPLv3" }
1010
classifiers = [
@@ -71,7 +71,7 @@ otf-batch-validator = "opentaskpy.cli.batch_validator:main"
7171
profile = 'black'
7272

7373
[tool.bumpver]
74-
current_version = "v25.3.0"
74+
current_version = "v25.3.1"
7575
version_pattern = "vYY.WW.PATCH[-TAG]"
7676
commit_message = "bump version {old_version} -> {new_version}"
7777
commit = true

src/opentaskpy/config/schemas/transfer/email/protocol.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
"smtp_server": {
1616
"type": "string"
1717
},
18+
"use_tls": {
19+
"type": "boolean"
20+
},
1821
"sender": {
1922
"type": "string",
2023
"pattern": "^(.*?\\s+<)?[\\w.-]+@[\\w.-]+\\.[a-zA-Z]{2,6}(>?)$"
@@ -33,6 +36,6 @@
3336
"additionalProperties": false
3437
}
3538
},
36-
"required": ["name"],
39+
"required": ["name", "smtp_server", "sender"],
3740
"additionalProperties": false
3841
}

src/opentaskpy/remotehandlers/email.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,22 +116,34 @@ def push_files_from_worker(
116116

117117
msg["From"] = self.protocol_vars["sender"]
118118

119+
# Set connection port, default to 587
120+
smtp_port = 587
121+
if "smtp_port" in self.protocol_vars:
122+
smtp_port = self.protocol_vars["smtp_port"]
123+
124+
# Determine whether to use startTLS on connection
125+
use_tls = True
126+
if "use_tls" in self.protocol_vars and not self.protocol_vars["use_tls"]:
127+
use_tls = False
128+
119129
# Send the email using a provided SMTP server
120130
try:
121131
self.logger.debug(f"Sending email to {email_address}")
122132
smtp = smtplib.SMTP(
123133
self.protocol_vars["smtp_server"],
124-
port=self.protocol_vars["smtp_port"],
134+
port=smtp_port,
125135
)
126136
if self.logger.getEffectiveLevel() <= DEBUG:
127137
smtp.set_debuglevel(1)
128-
smtp.starttls()
129-
130-
# Authenticate
131-
smtp.login(
132-
self.protocol_vars["credentials"]["username"],
133-
self.protocol_vars["credentials"]["password"],
134-
)
138+
if use_tls:
139+
smtp.starttls()
140+
141+
# Authenticate (if credentials specified)
142+
if "credentials" in self.protocol_vars:
143+
smtp.login(
144+
self.protocol_vars["credentials"]["username"],
145+
self.protocol_vars["credentials"]["password"],
146+
)
135147

136148
smtp.sendmail(
137149
self.protocol_vars["sender"], email_address, msg.as_string()

tests/test_email_transfer_schema_validate.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66

77
@pytest.fixture(scope="function")
88
def valid_protocol_definition():
9-
return {"name": "email"}
9+
return {
10+
"name": "email",
11+
"smtp_server": "smtp.gmail.com",
12+
"sender": "Test Sender <test@example.com>",
13+
}
1014

1115

1216
@pytest.fixture(scope="function")

tests/test_schema_validate.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ def valid_protocol_definition():
1616

1717
@pytest.fixture(scope="function")
1818
def valid_protocol_definition_2():
19-
return {"name": "email"}
19+
return {
20+
"name": "email",
21+
"smtp_server": "smtp.gmail.com",
22+
"sender": "Test Sender <test@example.com>",
23+
}
2024

2125

2226
@pytest.fixture(scope="function")

0 commit comments

Comments
 (0)