Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
archlinux
archversion
Commits
09282ac7
Commit
09282ac7
authored
Nov 18, 2018
by
Seblu
Browse files
Support full tls mode and port config for sendmail
parent
ad98138e
Changes
2
Hide whitespace changes
Inline
Side-by-side
misc/sendmail.conf.example
View file @
09282ac7
[sendmail]
# Options in this section are about sendmail command
#
M
ail address
#
To m
ail address
(mandatory)
# to = archversion@gmail.com
# From mail address
# from = archversion@gmail.com
# default value is archversion
# Mail subject
# subject = Archversion report
# default value is "Archversion report"
# SMTP server address (mandatory)
# host = smtp.honeypot.org
# SMTP server port
# port = 465
# default value is 25
# SMTP server
# smtp = smtp.honeypot.org
\ No newline at end of file
# SMTP server tls mode
# tls = no | starttls | yes
# default value is no
src/bin/archversion
View file @
09282ac7
...
...
@@ -30,7 +30,7 @@ from email.mime.text import MIMEText
from
email.utils
import
formatdate
from
io
import
StringIO
from
pprint
import
pprint
from
smtplib
import
SMTP
from
smtplib
import
SMTP
,
SMTP_SSL
import
argparse
import
logging
import
os
...
...
@@ -173,14 +173,19 @@ def command_sendmail(args, vctrl):
# check args
try
:
to
=
config
[
"mail"
][
"to"
]
from_
=
config
[
"mail"
].
get
(
"from"
,
"
A
rchversion
<noreply@archlinux.org>
"
)
from_
=
config
[
"mail"
].
get
(
"from"
,
"
a
rchversion"
)
subject
=
config
[
"mail"
].
get
(
"subject"
,
"Archversion Report"
)
smtp
=
config
[
"smtp"
][
"host"
]
host
=
config
[
"smtp"
][
"host"
]
port
=
config
[
"smtp"
].
get
(
"port"
,
"25"
)
login
=
config
[
"smtp"
].
get
(
"login"
)
password
=
config
[
"smtp"
].
get
(
"password"
)
start
tls
=
config
[
"smtp"
].
get
(
"
start
tls"
,
"
false
"
).
lower
()
in
(
"true"
,
"yes"
)
tls
=
config
[
"smtp"
].
get
(
"tls"
,
"
no
"
).
lower
()
except
KeyError
as
exp
:
raise
BaseError
(
"Unable to load sendmail config"
)
from
exp
# check tls param
tls_values
=
(
"yes"
,
"no"
,
"starttls"
)
if
tls
not
in
tls_values
:
raise
BaseError
(
"Invalid SMTP tls value: %s. Should be %s."
%
(
tls
,
"|"
.
join
(
tls_values
)))
# capture a report
stdout
=
StringIO
()
stdout_bak
=
sys
.
stdout
...
...
@@ -198,13 +203,18 @@ def command_sendmail(args, vctrl):
msg
[
"Date"
]
=
formatdate
(
localtime
=
True
)
# send the mail
try
:
s
=
SMTP
(
smtp
)
if
starttls
:
s
.
starttls
()
con
=
SMTP_SSL
()
if
tls
==
"yes"
else
SMTP
()
# since python3.7 we need to set host to establish ssl/tls connections
# this cannot be done in SMTP class contructor because it try to
# initiate the connection at that time
con
.
_host
=
host
con
.
connect
(
host
,
port
)
if
tls
==
"starttls"
:
con
.
starttls
()
if
login
:
s
.
login
(
login
,
password
)
s
.
send_message
(
msg
)
s
.
quit
()
con
.
login
(
login
,
password
)
con
.
send_message
(
msg
)
con
.
quit
()
except
Exception
as
exp
:
raise
BaseError
(
"Unable to send mail"
)
from
exp
...
...
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