def cleanup_mailboxes(): while True: now = time.time() expired = [addr for addrbox in mailboxes.items() if now - box['created'] > EXPIRY_SECONDS] for addr in expired: del mailboxes[addr] time.sleep(60)
@app.route('/send'methods=['POST']) def send_mail(): data = request.on to = data.get("to") if to in mailboxes: mailboxes[to]['emails'].append({ "from": data.get("from""anonymous@web"), "subject": data.get("subject""(No Subject)"), "body": data.get("body"""), "time": time.time() }) return onify({"status": "sent"}) return onify({"error": "Mailbox not found"})404
@app.route('/inbox/<mailbox>'methods=['GET']) def inbox(mailbox): if mailbox in mailboxes: return onify(mailboxes[mailbox]['emails']) return onify({"error": "Mailbox not found"})404
if __name__ == '__main__': threading.Thread(target=cleanup_mailboxesdaemon=True).start() app.run(debug=True)
🚀 使用示例(Postman 或 curl)
创建邮箱:
curl -X POST http://127.0.0.1:5000/create
发送邮件到临时邮箱:
curl -X POST http://127.0.0.1:5000/send -H "Content-Type: application/on" -d '{ "to": "[email protected]", "from": "[email protected]", "subject": "Hello", "body": "This is a test message" }'