0

although I can find a lot of similar questions regarding this failure, the suggestions/answers dont help my case so I am looking for some help. I have the following function which works perfectly fine on my development machine(Windows 7) but when I try to run it on another machine which is running a Windows Server 2012 R2 Standard OS, I get the "Errno 10061 - No connection could be made because the target machine actively refused it" failure. I have tried disabling the firewall on the machine but that didnt help. I know the port and SMTP server are correctly listening as the same code on my development machine works. How do I go about resolving this? Any help is appreciated

def send_email(user, pwd, recipient, subject, body):
  gmail_user = user
  gmail_pwd = pwd
  FROM = user
  TO = recipient if type(recipient) is list else [recipient]
  SUBJECT = subject
  TEXT = body

message = """From: %s\nTo: %s\nSubject: %s\n\n%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
try:
    server_ssl = smtplib.SMTP_SSL("smtp.gmail.com", 465)
    server_ssl.ehlo()
    # server_ssl.starttls()
    server_ssl.login(gmail_user, gmail_pwd)
    server_ssl.sendmail(FROM, TO, message)
    server_ssl.close()
    print 'successfully sent the mail'
except:
    print "failed to send mail"
Imran
  • 126
  • 2
  • 17

1 Answers1

0

the problem was the firewall blocking the connection. Once that was removed the script works

Imran
  • 126
  • 2
  • 17