Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
picomon
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
arn
picomon
Commits
d8598c06
Commit
d8598c06
authored
Jul 20, 2014
by
Jonathan Michalon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split send_email_for_check so we have a generic reusable send_email helper
parent
ee8bb1a0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
14 deletions
+23
-14
lib/mails.py
lib/mails.py
+23
-14
No files found.
lib/mails.py
View file @
d8598c06
...
...
@@ -71,6 +71,23 @@ _mailer = ThreadedSMTP()
def
quit
():
_mailer
.
quit
()
def
_send_email
(
subject
,
body
,
extra_headers
=
{}):
from
.
import
config
# encode / decode is a fix that didn't make it into Debian Wheezy
# http://bugs.python.org/issue16948
msg
=
MIMEText
(
body
.
encode
(
'utf-8'
).
decode
(
'latin1'
),
'plain'
,
'utf-8'
)
msg
[
'Subject'
]
=
subject
msg
[
'From'
]
=
config
.
emails
.
addr_from
msg
[
'To'
]
=
", "
.
join
(
config
.
emails
.
to
)
msg
[
'Date'
]
=
strftime
(
'%a, %d %b %Y %H:%M:%S %z'
)
for
(
key
,
val
)
in
extra_headers
.
items
():
msg
[
key
]
=
val
_mailer
.
sendmail
(
config
.
emails
.
addr_from
,
config
.
emails
.
to
,
msg
.
as_string
())
def
send_email_for_check
(
check
):
from
.
import
config
...
...
@@ -86,21 +103,13 @@ def send_email_for_check(check):
msg_text
+=
(
"Check %s failed:
\n
%s"
%
(
str
(
check
),
check
.
errmsg
.
strip
()))
# encode / decode is a fix that didn't make it into Debian Wheezy
# http://bugs.python.org/issue16948
msg
=
MIMEText
(
msg_text
.
encode
(
'utf-8'
).
decode
(
'latin1'
),
'plain'
,
'utf-8'
)
msg
[
'Message-ID'
]
=
make_msgid
(
type
(
check
).
__name__
)
extra_headers
=
{}
extra_headers
[
'Message-ID'
]
=
make_msgid
(
type
(
check
).
__name__
)
# if check is OK it's a follow up, so set In-Reply-To
if
check
.
ok
and
hasattr
(
check
,
'mails_msgid'
):
msg
[
'In-Reply-To'
]
=
check
.
mails_msgid
msg
[
'References'
]
=
check
.
mails_msgid
check
.
mails_msgid
=
msg
[
'Message-ID'
]
extra_headers
[
'In-Reply-To'
]
=
check
.
mails_msgid
extra_headers
[
'References'
]
=
check
.
mails_msgid
check
.
mails_msgid
=
extra_headers
[
'Message-ID'
]
msg
[
'Subject'
]
=
subject
msg
[
'From'
]
=
config
.
emails
.
addr_from
msg
[
'To'
]
=
", "
.
join
(
config
.
emails
.
to
)
msg
[
'Date'
]
=
strftime
(
'%a, %d %b %Y %H:%M:%S %z'
)
_send_email
(
subject
,
msg_text
,
extra_headers
)
_mailer
.
sendmail
(
config
.
emails
.
addr_from
,
config
.
emails
.
to
,
msg
.
as_string
())
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment