Skip to content

Commit

Permalink
automatic: allow use of STARTTLS/TLS
Browse files Browse the repository at this point in the history
Add the ability to use STARTTLS/TLS for sending e-mail via the `email`
emitter.

The `email_tls` option supports three settings: ``starttls``, used to
switch to TLS on plaintext ports like 25 or 587 and ``yes``, used to
wrap the entire connection in TLS, usually on port 465. Any other
setting (``off`` by default) will use plain unencrypted SMTP.

Note: this depends on rpm-software-management#1956 .

= changelog =
msg: Add `email_tls` option to DNF Automatic
type: enhancement
resolves: rpm-software-management#1954
  • Loading branch information
rathann committed Jun 28, 2023
1 parent 6c65b38 commit 97c093b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
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

0 comments on commit 97c093b

Please sign in to comment.