Forum Discussion

ZJoe's avatar
ZJoe
Frequent Visitor
1 year ago
Solved

Send email from notebook getting "SMTPHeloError: (501, b'5.5.4 Invalid domain name....."

Hi, I'm trying to send email with a python notebook, using smtplib. all the code works fine on my desktop using a py script, but when I migrate it to the notebook, it failed with error below:    ...
  • ZJoe's avatar
    ZJoe
    1 year ago

    Thanks for your try! but finally I need to add this notebook to a pipeline and make it running automatically, so using the VS Code may not help.

     

    And as you said, an invalid domain name may be generated in a Fabric portal, and I had found a same issue in stackoverflow (but it's not in a Fabric notebook) . 

    I tried to add the codes it mentioned, and it works, by explicitly setting sender host name in the ehlo command to anything lowercase.

     

    import smtplib
    server_365 = smtplib.SMTP('smtp.office365.com', '587')
    server_365.ehlo('mylowercasehost')
    server_365.starttls()
    server_365.ehlo('mylowercasehost')

     

     what's more, I found another way to write the code in the docs of smtplib, it also works, as follows:

     

    import smtplib
    server_365 = smtplib.SMTP('smtp.office365.com', '587', local_hostname='mylowercasehost')
    server_365.starttls()