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

When using an SMTP SSL connection,, get ValueError. #80275

Open
tyrone-zhao mannequin opened this issue Feb 23, 2019 · 5 comments
Open

When using an SMTP SSL connection,, get ValueError. #80275

tyrone-zhao mannequin opened this issue Feb 23, 2019 · 5 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir topic-email type-bug An unexpected behavior, bug, or error

Comments

@tyrone-zhao
Copy link
Mannequin

tyrone-zhao mannequin commented Feb 23, 2019

BPO 36094
Nosy @warsaw, @tiran, @bitdancer, @amcgregor, @dstufft, @csabella, @Tyrone-Zhao
PRs
  • bpo-36094: Fix a bug in smtplib module #11998
  • bpo-11998: Patch smtplib.py #23490
  • bpo-36094: Update smtplib.py #23635
  • Files
  • 1.png: How does it happen
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2019-02-23.17:44:01.948>
    labels = ['3.8', 'type-bug', '3.7', 'expert-email']
    title = 'When using an SMTP SSL connection,, get ValueError.'
    updated_at = <Date 2021-02-24.05:51:21.028>
    user = 'https://github.com/tyrone-zhao'

    bugs.python.org fields:

    activity = <Date 2021-02-24.05:51:21.028>
    actor = 'gertburger'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['email']
    creation = <Date 2019-02-23.17:44:01.948>
    creator = 'tyrone-zhao'
    dependencies = []
    files = ['48167']
    hgrepos = []
    issue_num = 36094
    keywords = ['patch']
    message_count = 4.0
    messages = ['336393', '336404', '376344', '377833']
    nosy_count = 10.0
    nosy_names = ['barry', 'christian.heimes', 'r.david.murray', 'amcgregor', 'python-dev', 'gertburger', 'dstufft', 'cheryl.sabella', 'tyrone-zhao', 'Dadeos']
    pr_nums = ['11998', '23490', '23635']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue36094'
    versions = ['Python 3.7', 'Python 3.8']

    @tyrone-zhao
    Copy link
    Mannequin Author

    tyrone-zhao mannequin commented Feb 23, 2019

    The following bug occurs when you connect after creating an instance of SMTP_SSL:

    import smtplib
    
    
    smtp_server = "smtp.163.com"
    con2 = smtplib.SMTP_SSL()
    con2.connect(smtp_server, 465)
    

    ValueError:
    server_hostname cannot be an empty string or start with a leading dot.
    File "E:\code\noUse.py", line 8, in <module>
    con2.connect(smtp_server, 465)

    @tyrone-zhao tyrone-zhao mannequin added performance Performance or resource usage 3.7 (EOL) end of life topic-email labels Feb 23, 2019
    @SilentGhost SilentGhost mannequin added 3.8 only security fixes type-bug An unexpected behavior, bug, or error and removed performance Performance or resource usage labels Feb 23, 2019
    @csabella
    Copy link
    Contributor

    tyrone-zhao, thank you for the report and the detail on the commit.

    Adding @christian.heimes to the nosylist as he added change this under bpo-19785 and @dstufft as he modified it to be self._host.

    @Dadeos
    Copy link
    Mannequin

    Dadeos mannequin commented Sep 4, 2020

    I wanted to enquire as to if/when the proposed PR11998 is likely to be merged?

    I also wanted to note the similarity between this issue and bpo-41470 and to suggest that whilst the change proposed in commit e445ccb of PR11998 [1] would be welcome, there may be a case for exposing the value ultimately passed as the server_hostname parameter to the SSLContext.wrap_socket(…) call [2] as a parameter to SMTP.connect(…) [3]. Doing so would aid potential use cases whereby the host parameter provided is an address, yet the TLS server hostname validation should be based upon another value (i.e. the hostname); potentially useful in scenarios where the host's address has been previously derived, by the caller, by other means (e.g. a call to socket.getaddrinfo(…) [4]).

    [1] e445ccb
    [2] https://docs.python.org/3/library/ssl.html#ssl.SSLContext.wrap_socket
    [3] https://docs.python.org/3/library/smtplib.html#smtplib.SMTP.connect
    [4] https://docs.python.org/3/library/socket.html#socket.getaddrinfo

    @amcgregor
    Copy link
    Mannequin

    amcgregor mannequin commented Oct 2, 2020

    Howdy! One of my projects, Marrow Mailer (formerly TurboMail) has received a bit of a flood of reports and erroneous pull requests attempting to correct this bug in the invocation of smtplib by Mailer.

    marrow/mailer#83 is our own tracking issue, with marrow/mailer#91 as the most "successful" pull request with more detailed (contextualized) traceback, comparison, and links to official documentation. (Also, yay, worked around the problem here by recovering my "native" issue tracker account rather than trying to sign in with GitHub.)

    This appears to be a clear regression. The particular reason why I'm unwilling to accept these patches to Mailer is that passing a hostname at SMTP_SSL instantiation time will cause the connection to be initiated from within __init__ itself, prior to any ability to set the diagnostic logging level, which is boo, hiss. Initializers actually doing things is un-good, beyond diagnostic logging not being an optional keyword argument. (Instantiation != procedural invocation.)

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @Leetcore
    Copy link

    I have a Ubuntu 22.04.3 LTS server with Python 3.10.12 and this exact problem: SMTP_SSL(hostname) just freezes!

    I found a workaround:

    conn = SMTP()
    conn._host = hostname
    conn.connect(hostname, 587)
    conn.starttls()
    conn.login(username, password)
    conn.sendmail(sender, destination, "body")
    conn.close()
    

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir topic-email type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants