python imaplib gpg 文件内容转换为消息
Lo,
imaplib 有一些问题。我正在尝试将 gpg 文件的内容放入电子邮件正文中。
加密文件看起来像这样:
ÕþëÂüÿΩfXаÕåº⁄H»[ßÖq«Ì5ßö
我的代码看起来像这样:
gpgFH = open(gpgFile, 'rb') gpgStr = gpgFH.read()
newEmail = email.message.Message() newEmail['主题'] = '废话' newEmail['From'] = '[电子邮件受保护]' newEmail['To'] = '[电子邮件受保护]' newEmail.set_payload(gpgStr+'\n') srv.append('INBOX', '', imaplib.Time2Internaldate(time.time()), str(newEmail))
当 gpgStr 为“hello”时,效果很好。当它是加密的胡言乱语时,它就没有作用。我猜unicode 在解决方案中的某个时刻抬起了丑陋的头,但我正在努力使其工作。
Lo,
Having some issues with imaplib. I'm trying to get the contents of a gpg file into the body of an email.
The encrypted file looks something like this:
ÕþëÂüÿΩfXаÕ庼H»[ßÖq«Ì5ßö
my code looks something like this:
gpgFH = open(gpgFile, 'rb') gpgStr = gpgFH.read()newEmail = email.message.Message() newEmail['Subject'] = 'blah' newEmail['From'] = '[email protected]' newEmail['To'] = '[email protected]' newEmail.set_payload(gpgStr+'\n') srv.append('INBOX', '', imaplib.Time2Internaldate(time.time()), str(newEmail))
When gpgStr is "hello" this works fine. When it is that encrypted jibberish, it dosent. I'm guessing unicode rears its ugly head at some point in the solution, but i'm struggling to make it work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试对文件数据进行 base64 编码。上面的代码将二进制数据放入电子邮件中,这是行不通的。
或者,您可能希望将 GPG 数据添加为附件而不是正文。
Try base64-encoding the file's data. The above code is putting binary data into the email, which isn't going to work.
Alternatively, you might want to add the GPG data as an attachment instead of the body.