📅  最后修改于: 2023-12-03 15:00:35.877000             🧑  作者: Mango
email_auth
email_auth
is a Python library for performing email authentication to improve email deliverability. It supports the following authentication mechanisms:
By using email_auth
, you can help ensure that your emails are delivered to your recipients' inboxes and increase the likelihood that they will be read.
To get started with email_auth
, you can install it using pip:
pip install email_auth
Once you have installed email_auth
, you can use it to authenticate emails in your Python program like this:
import email_auth
# Set up your authentication information
domain = 'example.com'
selector = 'default'
private_key = 'path/to/your/private/key'
public_key = 'path/to/your/public/key'
# Create a DKIM signer
signer = email_auth.DKIMSigner(domain, selector, private_key)
# Sign your email
signed_message = signer.sign(message)
# Create an SPF checker
checker = email_auth.SPFChecker(domain)
# Check the SPF record for the sender
result = checker.check(sender)
# Create a DMARC checker
checker = email_auth.DMARCChecker(domain, policy=DMARC_POLICY_REJECT)
# Check the DMARC record for the sender
result = checker.check(sender)
SPF is an email authentication mechanism that allows a domain owner to specify which IP addresses are authorized to send email on behalf of their domain. SPF works by adding a DNS record that specifies a list of IP addresses or hostnames that are allowed to send email for a particular domain.
email_auth
provides a simple way to check an email's SPF record and verify that the email is being sent from an authorized IP address. You can use the SPFChecker
class to perform this check.
DKIM is another email authentication mechanism that allows a domain owner to add a digital signature to their outgoing emails. The signature is added to the email header and is then verified by the recipient's email server. This verifies that the email was sent by the domain owner and has not been modified in transit.
email_auth
provides a simple way to sign emails using DKIM and to verify DKIM signatures on incoming emails. You can use the DKIMSigner
class to sign outgoing emails and the DKIMVerifier
class to verify the signatures on incoming emails.
DMARC is a protocol that works in conjunction with SPF and DKIM to provide even stronger email authentication. DMARC allows a domain owner to specify what action should be taken if an email fails both SPF and DKIM checks. The domain owner can choose to reject, quarantine, or simply monitor these emails.
email_auth
provides a simple way to check the DMARC policy for a domain using the DMARCChecker
class. You can use this class to check whether an email complies with the DMARC policy for the sender's domain.