我正在做一个项目,看起来在邮箱和提取数据的邮件。
我想提取所有的电子邮件地址在邮件正文中找到。
提取电子邮件地址:
# Python script to extract email addresses from email messages / eml
# Comment from JNevill solved the final bit
import os
import re
from email import policy
from email.parser import BytesParser
emaillocation = os.chdir(r"\\10.21.1.236\websites\vaccinatieplanner\mail\stroomz\onbezorgd")
emaillist = []
for emailmessage in os.listdir(emaillocation):
with open(f'{emailmessage}', 'rb') as em:
msg = BytesParser(policy=policy.default).parse(em)
emailmsgraw = msg.get_body(preferencelist=('plain', 'html'))
emailmsg = emailmsgraw.get_content()
emaillist.extend(re.findall(r'[\w.+-]+@[\w-]+\.[\w.-]+', emailmsg))
print(emaillist)
1条答案
按热度按时间wfypjpf41#
在JNevill的评论的帮助下,