I am currently attempting to attach a csv to an email but I keep getting errors, the code I have at the moment is this:
error_list=[{'error_1': 0, 'error_2':1}, {'error_1': 2, 'error_2': 1}]
with open('errors.csv', "w") as infile:
writer = csv.DictWriter(infile, fieldnames=error_list[0].keys())
writer.writeheader()
for data in error_list:
writer.writerow(data)
mail = EmailMessage(subject='Test', from_email=EMAIL_HOST_USER, to=['example@example.com',])
mail.attach('errors.csv', infile, 'text/csv')
mail.send()
I am not quite sure where I am going wrong - at the moment I am getting the error: 'Connection unexpectedly closed: [WinError 10054] An existing connection was forcibly closed by the remote host'