When trying to send the email with the host:cpanel.freehosting.com P it is raising an error like
This is my code:
import smtplib
s = smtplib.SMTP('cpanel.freehosting.com', 465)
s.starttls()
s.login("myusername", "mypassword")
message = "Message_you_need_to_send"
s.sendmail("myemailid", "receiver_email_id", message)
s.quit()
This is the error i got:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.5/smtplib.py", line 251, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python3.5/smtplib.py", line 337, in connect
(code, msg) = self.getreply()
File "/usr/lib/python3.5/smtplib.py", line 393, in getreply
raise SMTPServerDisconnected("Connection unexpectedly closed")
smtplib.SMTPServerDisconnected: Connection unexpectedly closed
Considering the port number you are using I'd try with
SMTP_SSLinstead ofSMTPandstarttls().https://docs.python.org/3/library/smtplib.html:
STARTTLSis a form of opportunistic TLS, it is supposed to be used with old protocols, that originally did't support TLS, to upgrade the connection. The port 465 was used before the introduction ofSTARTTLSforSMTPS, which is now deprecated.Alternatively you should be able to use port 25 with your original code.
In both examples you can completely omit the port number as you are using the default ports.