I have been trying to mail using python SMTPlib, but I am constantly getting the following error :
Traceback (most recent call last):
File "mailing.py", line 2, in <module>
server = smtplib.SMTP('mail.students.iitmandi.ac.in:587')
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 335, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python3.5/smtplib.py", line 306, in _get_socket
self.source_address)
File "/usr/lib/python3.5/socket.py", line 711, in create_connection
raise err
File "/usr/lib/python3.5/socket.py", line 702, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
I am new to python and have only tried mailing from PHP before. Please excuse my lack of knowledge on the topic. My python code is :
import smtplib
server = smtplib.SMTP('mail.students.iitmandi.ac.in:587')
server.starttls()
server.login("username","zxxxxx")
header = 'From: from_addr'
header += 'To: to_addr'
header += 'Subject:'
message = "bmnbjbj"
message = header + message
server.sendmail("from_addr","to_addr",message)
I am sure of my SMTP server details because I am using the same configuration in my Gmail app to communicate using this email.