Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
PythonLibs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
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
TheCodeLabs
PythonLibs
Commits
5dacb367
Commit
5dacb367
authored
4 years ago
by
Robert Goldmann
Browse files
Options
Downloads
Patches
Plain Diff
added MailHandler
parent
5ebfb82c
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
PythonLibs/MailHandler.py
+50
-0
50 additions, 0 deletions
PythonLibs/MailHandler.py
PythonLibs/__init__.py
+1
-0
1 addition, 0 deletions
PythonLibs/__init__.py
with
51 additions
and
0 deletions
PythonLibs/MailHandler.py
0 → 100644
+
50
−
0
View file @
5dacb367
import
smtplib
import
ssl
from
email.mime.multipart
import
MIMEMultipart
from
email.mime.text
import
MIMEText
from
typing
import
List
,
Dict
class
MailHandler
:
@staticmethod
def
send_from_config
(
config
:
Dict
,
subject
:
str
,
content
:
str
):
MailHandler
.
send
(
config
[
'
host
'
],
config
[
'
port
'
],
config
[
'
userName
'
],
config
[
'
password
'
],
config
[
'
receiverMails
'
],
subject
,
content
)
@staticmethod
def
send
(
host
:
str
,
port
:
int
,
userName
:
str
,
password
:
str
,
receiverMails
:
List
[
str
],
subject
:
str
,
content
:
str
):
message
=
MIMEMultipart
(
'
alternative
'
)
message
[
'
Subject
'
]
=
subject
message
[
'
From
'
]
=
userName
message
[
'
To
'
]
=
receiverMails
# Create the plain-text and HTML version of your message
text
=
subject
html
=
'''
\
<html>
<body>
<h2>{subject}</h2>
{content}
</body>
</html>
'''
.
format
(
subject
=
subject
,
content
=
content
)
# Turn these into plain/html MIMEText objects
part1
=
MIMEText
(
text
,
'
plain
'
)
part2
=
MIMEText
(
html
,
'
html
'
)
# Add HTML/plain-text parts to MIMEMultipart message
# The email client will try to render the last part first
message
.
attach
(
part1
)
message
.
attach
(
part2
)
# Create secure connection with server and send email
context
=
ssl
.
create_default_context
()
with
smtplib
.
SMTP_SSL
(
host
,
port
,
context
=
context
)
as
server
:
server
.
login
(
userName
,
password
)
server
.
sendmail
(
userName
,
receiverMails
,
message
.
as_string
())
This diff is collapsed.
Click to expand it.
PythonLibs/__init__.py
+
1
−
0
View file @
5dacb367
from
PythonLibs.DefaultLogger
import
DefaultLogger
from
PythonLibs.MailHandler
import
MailHandler
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