"""\nimport smtplib\nimport imaplib\nfrom email.mime.text import MIMEText\n\n# 发送邮件\ndef send_email():\n # 邮件内容\n msg = MIMEText('This is a test email')\n msg['Subject'] = 'Test Email'\n msg['From'] = 'sender@example.com'\n msg['To'] = 'recipient@example.com'\n\n # 连接SMTP服务器并发送邮件\n smtp_server = 'smtp.example.com'\n smtp_port = 587\n username = 'sender@example.com'\n password = 'password'\n server = smtplib.SMTP(smtp_server, smtp_port)\n server.starttls()\n server.login(username, password)\n server.sendmail(msg['From'], msg['To'], msg.as_string())\n server.quit()\n\n# 保存已发送邮件到"Sent Items"文件夹\ndef save_sent_email():\n # 连接IMAP服务器\n imap_server = 'imap.example.com'\n username = 'sender@example.com'\n password = 'password'\n server = imaplib.IMAP4(imap_server)\n server.login(username, password)\n\n # 选择"Sent Items"文件夹\n server.select('Sent Items')\n\n # 获取最新的邮件\n status, response = server.search(None, 'ALL')\n email_ids = response[0].split()\n latest_email_id = email_ids[-1]\n\n # 将最新的邮件移动到"Sent Items"文件夹\n server.store(latest_email_id, '+X-GM-LABELS', '\Sent')\n\n # 关闭连接\n server.close()\n server.logout()\n\n# 发送邮件\nsend_email()\n\n# 保存已发送邮件到"Sent Items"文件夹\nsave_sent_email()\n"""\n\n在这个示例中,我们首先定义了一个send_email函数,它使用Python的SMTP库来发送一封邮件。然后,我们定义了一个save_sent_email函数,它使用Python的IMAP库连接到Outlook邮箱,选择"Sent Items"文件夹,并将最新的邮件移动到该文件夹。\n\n请确保将示例代码中的SMTP服务器、端口、用户名和密码替换为您自己的信息,并根据需要修改邮件的内容、主题、发件人和收件人。\n\n请注意,由于Outlook的IMAP实现可能会有所不同,您可能需要根据您的具体环境进行适当的调整。


原文地址: https://www.cveoy.top/t/topic/pqPD 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录