This commit is contained in:
guoyz 2025-04-21 21:57:41 +08:00
parent 1378b7f87b
commit a2faa7c616

View File

@ -5,7 +5,7 @@ from email.header import decode_header
from email.mime.text import MIMEText
from imapclient import IMAPClient
from email.parser import Parser
import base64
def send_email(subject, body, to_email):
# 这个函数名为send_email它接受三个参数
# subject邮件主题、body邮件内容和to_email收件人的电子邮件地址
@ -52,15 +52,9 @@ def get_latest_email_body(to_email):
# print(f"Search Status: {status}")
print(f"Matching Emails: {messages}")
response = mail.fetch(messages, ['FLAGS', 'RFC822.SIZE'])
# `response` is keyed by message id and contains parsed,
# converted response items.
for message_id, data in response.items():
print('{id}: {size} bytes, flags={flags}'.format(
id=message_id,
size=data[b'RFC822.SIZE'],
flags=data[b'FLAGS']))
for msgid, data in mail.fetch(messages, ['ENVELOPE']).items():
envelope = data[b'ENVELOPE']
print('ID #%d: "%s" received %s' % (msgid, envelope.subject.decode(), envelope.date))
if __name__ == "__main__":
@ -72,8 +66,8 @@ if __name__ == "__main__":
# 'vendor': 'myclient',
# 'support-email': 'yizeguo1@126.com'
# }
body = get_latest_email_body("guoyize2209@163.com")
get_latest_email_body("guoyize2209@163.com")
# if body:
# print("Latest email body:", body)
# else:
# print("No plain text email found.")
# print("No plain text email found.")