0

I'm trying to log into the SMTP server. The custom domain is not able to be recognized through the smtplib.SMTP host parameter.

Have Tried:

SMTP host for gmail domains

    # login smtp server
    # Issue
    server = smtplib.SMTP(host="smtp.gmail.com", port=587)
    #

    print(server)
    server.ehlo()
    server.starttls()
    print(username, email, app_password)
    server.login(username, app_password)
    print("logged in")
    server.sendmail(from_email, to_emails, msg_str)
    server.quit()

Not Working:

SMTP host for custom domain

    # login smtp server
    # Issue
    server = smtplib.SMTP(host="smtp.customDomain.io", port=587)
    #

    print(server)
    server.ehlo()
    server.starttls()
    print(username, email, app_password)
    server.login(username, app_password)
    print("logged in")
    server.sendmail(from_email, to_emails, msg_str)
    server.quit()
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • 1
    Have you checked the logs on the SMTP server for the custom domain, to see why it's rejecting the login? – Barmar Aug 21 '23 at 19:26
  • I checked the logs from printing the variable server. server = smtplib.SMTP. However, there's no response from running this line. – Peter Kim Aug 21 '23 at 19:28
  • I mean the logs on `smtp.customDomain.io`. – Barmar Aug 21 '23 at 19:29
  • Unfortunately, I'm not getting any response from smtp.customDomain.io. – Peter Kim Aug 21 '23 at 19:30
  • 1
    That sounds like a firewall problem. – Barmar Aug 21 '23 at 19:36
  • That still didn't resolve the issue. However, thanks for your help! – Peter Kim Aug 21 '23 at 19:53
  • Use a packet capture application like Wireshark to see where the connection is getting stuck. – Barmar Aug 21 '23 at 19:59
  • Try manually with telnet, from the same machine where you run your Python code: `telnet smtp.customdomain.io 587`. You should see a SMTP greeting like "220 service ready" or such. Enter "ehlo me" and see if it replies. Use "quit" to get out. If there is no such server reply, check the port. Usually unencrypted SMTP runs on port 25, not 587. Your code looks like you want a plain connection and upgrade it to encrypted with `starttls`. – Robert Aug 21 '23 at 22:00

0 Answers0