I can sent emails from a perl script but not from a python script.
I've created a perl script that runs on a daily basis via jenkins and if some checks fails it sends me an email.
I'm trying to migrate the script from perl to python3.7 but can't send an email from python.
This is the code in perl:
use strict;
use warnings;
use Email::MIME;
use Email::Sender::Simple qw(sendmail);
use Data::Dumper;
my $message = Email::MIME->create(
header_str => [
From => 'my_email@domain.com',
To => $email,
Subject => 'just a subject',
],
attributes => {
encoding => 'quoted-printable',
charset => 'ISO-8859-1',
},
body_str => $arr_msg,
);
my $email_test = sendmail($message);
}
This is the code in python:
import smtplib
server = smtplib.SMTP('127.0.0.1', 25) # also tried my-domain.com with port 2525
server.sendmail(
"me@my-domain.com",
"someone@address.com",
"this message is from python")
server.quit()
It dies at server = smtplib.SMTP('127.0.0.1', 25) with error:
smtplib.SMTPServerDisconnected: Connection unexpectedly closed
Output of lsof -i :25
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
master 2728 root 12u IPv4 1774572613 0t0 TCP
localhost.localdomain:smtp (LISTEN)
What could it be?