Manually signing an email with DKIM in Python

你离开我真会死。 提交于 2019-12-05 10:50:51

if I remember correctly, dkim.sign expects the full message source as parameter, but you are passing a MIMEText object.

try passing text.as_string() instead

sig = dkim.sign(text.as_string(), .... )

python3 enforces a strong difference between processing bytes and string.

the easiest way I found to avoid conversion when using the dkim module is to stay in bytes, here is what I use:

from email.parser import BytesParser
import dkim

mail = BytesParser().parse (open('mail.eml', 'rb'))

print(dkim.verify( mail.as_bytes () ) )))

The "rb" is for opening the file in bytes mode.

Give it a try.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!