marrow / mailer

A light-weight, modular, message representation and mail delivery framework for Python.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tlsv1 unrecognized name (_ssl.c:600) when setting up with gmail

jerrygaoLondon opened this issue · comments

Following the example code, i'm trying to setup marrow.mailer with gmail. There is no indication for any failure. But, after debugging, it actually throws [SSL: TLSV1_UNRECOGNIZED_NAME] tlsv1 unrecognized name (_ssl.c:600) in result

My code is as follows:

    import logging
    from marrow.mailer import Message, Mailer
    logging.basicConfig(level=logging.DEBUG)

    mail = Mailer({
        'manager.use': 'futures',
        'transport.use': 'smtp',
        'transport.host': 'smtp.gmail.com',
        'transport.port': '587',
        'transport.tls': 'required',
        'transport.username': '<MY_USERNAME>@gmail.com',
        'transport.password': '<MY_PASSWORD>',
        'transport.max_messages_per_connection': 5,
        'transport.debug': 'True'
    })
    mail.start()

    message = Message([('recipient 1', '<recipient1_email_address>')],
                      [('recipient 2', '<recipient1_email_address>')],
                      "This is a test message.", plain="Testing!")

    result = mail.send(message)
    mail.stop()

With exactly same setting, using smtplib works well.

Did you end up making progress on this?

Looks like this might have something to do with SNI.

Unfortunately, smtplib is becoming a lot easier to use, so I'm going to migrate to that until this is fixed.

commented

You can fix it very simple.
Just edit you local copy of marrow.mailer transport/smtp.py
row 74
from
connection = SMTP(local_hostname=self.local_hostname, timeout=self.timeout)
to
connection = SMTP(host=self.host, port=self.port, local_hostname=self.local_hostname, timeout=self.timeout)

And
row 84
from
connection.starttls(self.keyfile, self.certfile)
to
connection.starttls()

Reaaly, U can make changes more effective for you. But this code show an idea for U.

Closing as… "won't fix"? "Already fixed?" "Upstream issue, not my problem?"

See the discussion on #83 and the associated (rejected) pull requests. This "fix", while seemingly required until CPython fix their ████, suffers a notable disadvantage. It is, however, conditionally applied in situations where it is required in my downstream work branch:

marrow/mailer/transport/smtp.py

Applying this fix will immediately attempt to connect on instantiation, not first use, and prevents the assignment of a debug level for diagnostic use prior to that attempt to connect. It's a "fix, with defects," which made those PRs unacceptable.

With slack time to update my projects, this fix will get incorporated "Real Soon Now™", once I get a chance to finish off modernized Python 3 packaging.