Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 30091

DKIM valid when sending e-mail via Python's SMTP without PDF attachment but not valid when attachment is included

$
0
0

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.


Viewing all articles
Browse latest Browse all 30091


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>