Skip to content

Commit cfd1a93

Browse files
authored
Adjust schema for email destinations to make startTLS and credentials optional, and require smtp server and sender to be set
1 parent 41358b1 commit cfd1a93

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@
1010
"smtp_port": {
1111
"type": "number",
1212
"minimum": 1,
13-
"maximum": 65535
13+
"maximum": 65535,
14+
"default": 25
1415
},
1516
"smtp_server": {
1617
"type": "string"
1718
},
19+
"start_tls": {
20+
"type": "boolean",
21+
"default": true
22+
},
1823
"sender": {
1924
"type": "string",
2025
"pattern": "^(.*?\\s+<)?[\\w.-]+@[\\w.-]+\\.[a-zA-Z]{2,6}(>?)$"
@@ -33,6 +38,6 @@
3338
"additionalProperties": false
3439
}
3540
},
36-
"required": ["name"],
41+
"required": ["name", "smtp_server", "sender"],
3742
"additionalProperties": false
3843
}

src/opentaskpy/remotehandlers/email.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,15 @@ def push_files_from_worker(
125125
)
126126
if self.logger.getEffectiveLevel() <= DEBUG:
127127
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-
)
128+
if self.protocol_vars["start_tls"]:
129+
smtp.starttls()
130+
131+
# Authenticate (if credentials specified)
132+
if self.protocol_vars["credentials"]:
133+
smtp.login(
134+
self.protocol_vars["credentials"]["username"],
135+
self.protocol_vars["credentials"]["password"],
136+
)
135137

136138
smtp.sendmail(
137139
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")

0 commit comments

Comments
 (0)