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 1 commit
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
Next Next commit
automatic: allow use of STARTTLS/TLS
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 #1956 .

= changelog =
msg: Add `email_tls` option to DNF Automatic
type: enhancement
resolves: #1954
  • Loading branch information
rathann committed Aug 31, 2023
commit 0ddb2e6ff67e5c6ce568449a9927209ffcbe6800
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