Lumos
Lumos

Reputation: 610

No connection could be made. ConnectionRefusedError

I try to make simple script that will send me the calculations results, after each launch of another script.

There is code, that sends message:

import pandas as pd
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

HOST = 'smtp.yandex.ru'
PORT = 587
SUBJECT = 'accuracy score'
TO = 'my email address'
FROM = 'another email address'
PASSWORD = 'the password from my email'

msg = MIMEMultipart()
msg['Subject'] = SUBJECT

message = 'Period: %s with true peaks accuracy = %s, \
                       and false peaks accuracy = %s'%(period, true_peaks, false_peaks)
msg.attach(MIMEText(message, 'plain'))

server = smtplib.SMTP(HOST, PORT)
server.ehlo()
server.starttls()
server.login(FROM, PASSWORD)

server.sendmail(FROM,  TO, msg.as_string())
server.quit()

But get an ConnectionRefusedError:

ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

Topic I've seen already:

The last link have the answer for @gmail. But i would like to use @yandex.

My system Windows 10 64Bit Python ver. Python 3.7.0

I see that main problem in my computer, but how to fix it? Or is there another decisons to send email automaticaly?

Thank you in advance!

Upvotes: 1

Views: 852

Answers (1)

Alderven
Alderven

Reputation: 8260

I successfully sent email from yandex email:

import smtplib as smtp

HOST = 'smtp.yandex.ru'
SUBJECT = 'accuracy score'
TO = 'my email address'
FROM = 'another email address'
PASSWORD = 'the password from my email'

period = 0
true_peaks = 1
false_peaks = 2
message = 'Period: %s with true peaks accuracy = %s, and false peaks accuracy = %s' % (period, true_peaks, false_peaks)
message = 'From: {}\nTo: {}\nSubject: {}\n\n{}'.format(FROM, TO, SUBJECT, message)

server = smtp.SMTP_SSL(HOST)
server.ehlo(FROM)
server.login(FROM, PASSWORD)
server.auth_plain()
server.sendmail(FROM, TO, message)
server.quit()

Email in my mailbox:

enter image description here

Upvotes: 1

Related Questions