Skip to content
Advertisement

Python smtp.connect does not connect

I’m writing a small python script to send an email, but my code isn’t even getting past smtp connection. I’m using the following code, but I never see “Connected”. Additionally, I’m not seeing an exception thrown, so I think it’s hanging on something.

JavaScript

Advertisement

Answer

Port 465 is for SMTPS; to connect to SMTPS you need to use the SMTP_SSL; however SMTPS is deprecated, and you should be using 587 (with starttls). (Also see this answer about SMTPS and MSA).

Either of these will work: 587 with starttls:

JavaScript

or 465 with SMTP_SSL.

JavaScript
Advertisement