I checked my e-mails with https://www.mail-tester.com/ and when sending an e-mail with an attachment it says that the DKIM signature is not valid. This error does not come up if I do not include the attachment. My code:
from email.message import EmailMessage
import smtplib, ssl
msg = EmailMessage()
msg['Subject'] = subject
msg['From'] = "{0} <{1}>".format(company_name, mail_address)
msg['To'] = email
msg.set_content(plain_text)
msg.add_alternative(html_string.format(name=name), subtype='html')
files = [path+file_attachement]
for file in files:
with open(file, 'rb') as f:
file_data = f.read()
file_name = 'pdf_name'
msg.add_attachment(file_data, maintype='application/pdf', subtype='pdf', filename=file_name)
with smtplib.SMTP(server, port, timeout=30) as smtp:
smtp.ehlo()
smtp.starttls(context=context)
smtp.ehlo()
smtp.login(mail_address, mail_password)
try:
smtp.send_message(msg)
print('Email to {} successfully sent!\n'.format(email))
smtp.quit()
except Exception as e:
print('\n Email to {} could not be sent :( because {}'.format(email, str(e)))
What could be the issue here? The PDF is fine, just a simple PDF file...
Thanks in advance.