[Python] Implementing DKIM or SPF in a Python package

Discussão em 'Python' iniciado por Stack, Abril 17, 2025.

  1. Stack

    Stack Membro Participativo

    (I’m a bit vague about how email authentication works, so please bear with me).

    I am writing a Python application which will send an email. This app is then packaged using PyInstaller so that it can be deployed to other non-Python users.

    I’ve got it working to some extent. The technique I use is:

    • Create a message with email.message.EmailMessage() from the email module.
    • Possibly include an attached file, using mimetypes.guess_type() from mimetypes to work out the mime type.
    • Get the recipient’s mail server using email.utils.parseaddr().
    • Use dns.resolver.resolve() from dns.resolver to find the MX for the recipient.
    • use smtplib.SMTP to build and send the email.

    All of this works for the most part. However, for recipients such as GMail addresses this fails since this isn’t authorised with either SPF or DKIM.

    I’m getting the impression that I should try to implement DKIM using something like dkimpy.

    The thing is that I don’t want to depend on a different MTA or DNS server, but only on what’s in the Python package.

    The question is: is it possible to implement DKIM (or SPF) purely in a Python package.

    Continue reading...

Compartilhe esta Página