Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
GÉANT Service Orchestrator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GÉANT Orchestration and Automation Team
GAP
GÉANT Service Orchestrator
Commits
adf4af61
Verified
Commit
adf4af61
authored
1 year ago
by
Karel van Klink
Browse files
Options
Downloads
Patches
Plain Diff
add skeleton email service
parent
550e2a6e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!161
Feature/add mailer service
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
gso/services/mailer.py
+26
-0
26 additions, 0 deletions
gso/services/mailer.py
gso/settings.py
+12
-0
12 additions, 0 deletions
gso/settings.py
with
38 additions
and
0 deletions
gso/services/mailer.py
0 → 100644
+
26
−
0
View file @
adf4af61
"""
The mailer service sends notification emails, as part of workflows that require interaction with external parties.
"""
import
smtplib
from
email.message
import
EmailMessage
from
gso.settings
import
load_oss_params
def
send_mail
(
recipient
,
subject
,
body
)
->
None
:
"""
Send an email message to the given address.
:param recipient: The destination address.
:param subject: The email subject.
:param body: The contents of the email message.
"""
email_params
=
load_oss_params
().
EMAIL
msg
=
EmailMessage
()
msg
[
"
From
"
]
=
email_params
.
from_address
msg
[
"
To
"
]
=
recipient
msg
[
"
Subject
"
]
=
subject
msg
.
set_content
(
body
)
with
smtplib
.
SMTP
(
email_params
.
smtp_host
,
email_params
.
smtp_port
)
as
s
:
if
email_params
.
smtp_username
or
email_params
.
smtp_password
:
s
.
login
(
email_params
.
smtp_username
,
email_params
.
smtp_password
)
s
.
send_message
(
msg
)
This diff is collapsed.
Click to expand it.
gso/settings.py
+
12
−
0
View file @
adf4af61
...
...
@@ -152,6 +152,17 @@ class NetBoxParams(BaseSettings):
api
:
str
class
EmailParams
(
BaseSettings
):
"""
Parameters for the email service.
"""
# TODO: Use more strict types after we've migrated to Pydantic 2.x
from_address
:
str
smtp_host
:
str
smtp_port
:
int
smtp_username
:
str
|
None
=
""
smtp_password
:
str
|
None
=
""
class
OSSParams
(
BaseSettings
):
"""
The set of parameters required for running :term:`GSO`.
"""
...
...
@@ -162,6 +173,7 @@ class OSSParams(BaseSettings):
PROVISIONING_PROXY
:
ProvisioningProxyParams
CELERY
:
CeleryParams
THIRD_PARTY_API_KEYS
:
dict
[
str
,
str
]
EMAIL
:
EmailParams
def
load_oss_params
()
->
OSSParams
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment