生成DKIM签名通过Python自定义MTA [英] Generating DKIM signatures VIA Python for Custom MTA

查看:523
本文介绍了生成DKIM签名通过Python自定义MTA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,我不完全DKIM丢失。我所知道的编码和设置DNS记录的一般规则与你的公钥等什么我有是结合了对飞出站电子邮件的签名和注入我的头的问题,因为我的MTA是定制的,写在蟒蛇从地上爬起来,不开箱。想知道如果任何人有,甚至发送1电子邮件DKIM,并通过所有的走过场的一个小蟒蛇的例子。就像使用在你的DNS设置的姐姐(公共)密钥相匹配的私有密钥生成256位加密的身体。

Ok, so I am not completely lost with DKIM. I know the general rules of encoding and setting DNS records with your public key, etc. What I am having issues with is incorporating the "on the fly" signing of outbound emails and injecting into my header because my MTA it is custom, written in python from the ground up, not out of the box. Wondering if anyone had a small python example of sending even 1 email with DKIM, and going through all the motions. Like generating the 256 bit crypto body using your private key that matches the sister (public) key in your dns settings.

推荐答案

这应该帮助。

https://launchpad.net/dkimpy

我看着包含在项目的测试,以及命令行工具来学习如何使用它。

I looked at the tests and the command line tools included in the project to learn how to use it.

下面是一个code片段,这将给你如何使用它的想法。对不起,我不能提供更多的。

Here is a code fragment which will give you an idea of how to use it. Sorry I can't provide more.

    self.dkim_private = open(os.path.join(settings.PROJECT_DIR, 'private_key.pem')).read()
    ... snip ...
    msg = MIMEMultipart('alternative')
    msg['From'] = "{0} <{1}>".format(self.sendfrom_name, self.sendfrom)
    msg['To'] = self.sendto
    msg['Date'] = formatdate(localtime=True)
    msg['Message-ID'] = self.message_id
    msg['Subject'] = self.subject

    msg.attach(MIMEText(unicodedata.normalize('NFKD', self.body_text), 'plain'))
    msg.attach(MIMEText(self.body, 'html'))

    sig = dkim.sign(msg.as_string(), 'myselector',
                    from_domain, self.dkim_private,
                    include_headers=['from', 'to', 'subject', 'message-id'])
    msg['DKIM-Signature'] = sig[len("DKIM-Signature: "):]

然后你使用可以使用到的smtplib发送电子邮件。

Then you use can use smtplib to send the email.

的私有和公共密钥可以很容易地在这里产生的:

The private and public keys can be generated easily here:

https://www.port25.com/support/domainkeysdkim-wizard/

这篇关于生成DKIM签名通过Python自定义MTA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆