本文介绍了Python - 使用附件转发IMAP电子邮件(imaplib,smtplib)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法使用附件转发邮件。任何人都可以指向正确的方向吗?我猜这是在Fetch语句,但不确定。
I'm having trouble forwarding mail with attachments. Can anyone point me in the right direction? I'm guessing it's in the Fetch statement but am unsure.
import sys
import uuid
import re
import smtplib
import email
address = ''
username = ''
password = ''
def checkMail():
M = imaplib.IMAP4_SSL(address)
M.login(username, password)
M.select("INBOX", readonly=True)
typ, data = M.search(None, 'Unseen')
messageCount = len(data[0].split())
print('messageCount: %', messageCount)
if messageCount > 0:
for num in data[0].split():
typ, data = M.fetch(num, '(BODY[TEXT])')
foundAt = data[0][1].find('Content-Type: application')
if(foundAt > 0):
print('attachmentfound')
sendMail(data[0][1])
M.close()
M.logout()
def sendMail(raw_message):
toAddress = ''
fromAddress = ''
LOGIN = ''
PASSWORD = ''
server = smtplib.SMTP('', 587)
server.set_debuglevel(1)
server.ehlo()
server.starttls()
server.login(LOGIN, PASSWORD)
server.sendmail(fromAddress, toAddress, raw_message)
server.quit()
def main():
checkMail()
main()
推荐答案
这是提取...添加一个提取(BODY [])做了伎俩。
It was the fetch... adding a fetch for (BODY[]) did the trick.
这篇关于Python - 使用附件转发IMAP电子邮件(imaplib,smtplib)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!