Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

automatic: allow use of STARTTLS/TLS #1957

Merged
merged 4 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ DNF CONTRIBUTORS
Christopher Meng <[email protected]>
Daniel Mach <[email protected]>
Dave Johansen <[email protected]>
Dominik Mierzejewski <[email protected]>
Dylan Pindur <[email protected]>
Eduard Cuba <[email protected]>
Evan Goode <[email protected]>
Expand Down
8 changes: 7 additions & 1 deletion dnf/automatic/emitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def commit(self):
email_from = self._conf.email_from
email_to = self._conf.email_to
email_port = self._conf.email_port
email_tls = self._conf.email_tls
message['Date'] = email.utils.formatdate()
message['From'] = email_from
message['Subject'] = subj
Expand All @@ -104,7 +105,12 @@ def commit(self):

# Send the email
try:
smtp = smtplib.SMTP(self._conf.email_host, self._conf.email_port, timeout=300)
if self._conf.email_tls == 'yes':
smtp = smtplib.SMTP_SSL(self._conf.email_host, self._conf.email_port, timeout=300)
else:
smtp = smtplib.SMTP(self._conf.email_host, self._conf.email_port, timeout=300)
if self._conf.email_tls == 'starttls':
smtp.starttls()
smtp.sendmail(email_from, email_to, message.as_string())
smtp.close()
except OSError as exc:
Expand Down
1 change: 1 addition & 0 deletions dnf/automatic/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ def __init__(self):
self.add_option('email_from', libdnf.conf.OptionString("root"))
self.add_option('email_host', libdnf.conf.OptionString("localhost"))
self.add_option('email_port', libdnf.conf.OptionNumberInt32(25))
self.add_option('email_tls', libdnf.conf.OptionString("no"))


class CommandConfig(Config):
Expand Down
5 changes: 5 additions & 0 deletions doc/automatic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ The email emitter configuration.

Port number to connect to at the SMTP server.

``email_tls``
either one of ``no``, ``yes``, ``starttls``, default: ``no``

Whether to use TLS, STARTTLS or no encryption to connect to the SMTP server.

``email_to``
list, default: ``root``

Expand Down
4 changes: 4 additions & 0 deletions etc/dnf/automatic.conf
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ email_host = localhost
# Port number to connect to at the email host.
email_port = 25

# Use TLS or STARTTLS to connect to the email host.
email_tls = no


[command]
# The shell command to execute. This is a Python format string, as used in
# str.format(). The format function will pass a shell-quoted argument called
Expand Down