Thanks to visit codestin.com
Credit goes to github.com

Skip to content

mailer python 3.8.5 issue. #5595

@shasan-marsdd

Description

@shasan-marsdd

CKAN version
2.9.0
Describe the bug
This bug appears when trying to use mailer with tls protocol turned on in python 3.8.5. All I'm trying to use the mailer package to email something in the background worker. It seems to be an issue related to smtplib build into python where the connect does not set the object variable _host in teh SMTP class. We need to do this right at the instantiation in order to set this variable in order for the starttls function to work. This doesn't seem to be an issue with Python 2.7 but is an issue in Python 3.8.5

Steps to reproduce
Steps to reproduce the behavior:
my module has similar to following

import ckan.lib.mailer as mailer
try:
# send email
email = {'recipient_name': recipient['display_name'],
'recipient_email': recipient['email'],
'subject': email_dict['subject'],
'body': email_dict['body'],
# 'headers': {'header1': 'value1'}
}
mailer.mail_recipient(**email)

except mailer.MailerException as e:
    raise

I recommend we simply move line 68 to line 84 on file ckan/lib/mailer.py, but pass the first argument as the host name right there. Also to catch SMTPConnectError as well.

Expected behavior
A clear and concise description of what you expected to happen.
I expected to successfully start tls and run the code above.

Additional details
Traceback (most recent call last):
File "/Users/shasan/PycharmProjects/ckan/ckan/lib/mailer.py", line 97, in _mail_recipient
smtp_connection.starttls()
File "/Users/shasan/.pyenv/versions/3.8.5/lib/python3.8/smtplib.py", line 774, in starttls
self.sock = context.wrap_socket(self.sock,
File "/Users/shasan/.pyenv/versions/3.8.5/lib/python3.8/ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "/Users/shasan/.pyenv/versions/3.8.5/lib/python3.8/ssl.py", line 1031, in _create
self._sslobj = self._context._wrap_socket(
ValueError: server_hostname cannot be an empty string or start with a leading dot.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions