主流临时邮箱服务排行榜
1. Nimail (www.nimail.cn)
- 特点:中文界面简洁,邮箱有效期24小时
- 优势:无需注册,自动生成邮箱地址
- 缺点:不支持自定义前缀
2. Temp-Mail (temp-mail.org)
- 特点:国际知名服务,支持多语言
- 优势:可自定义邮箱前缀,支持API
- 缺点:广告较多
3. 10分钟邮箱 (10minutemail.com)
- 特点:邮箱10分钟后自动销毁
- 优势:适合短期验证需求
- 缺点:时间太短可能不够用
4. Guerrilla Mail (www.guerrillamail.com)
- 特点:专注匿名邮箱15年
- 优势:支持发送邮件,历史记录完整
- 缺点:界面较老旧
Python自动获取临时邮箱邮件
以Nimail为例,我们可以用Python自动获取临时邮箱中的邮件内容。虽然Nimail没有公开API,但可以通过模拟浏览器操作实现。
安装必要库
pip install requests beautifulsoup4
示例代码
import requests
from bs4 import BeautifulSoup
import time
import random
class NimailClient:
def __init__(self):
self.base_url = "https://www.nimail.cn"
self.session = requests.Session()
self.current_email = ""
def generate_email(self):
"""生成随机邮箱"""
response = self.session.get(f"{self.base_url}/new")
if response.status_code == 200:
self.current_email = response.text.strip()
print(f"生成新邮箱: {self.current_email}")
return self.current_email
return None
def check_mails(self):
"""检查邮箱中的邮件"""
if not self.current_email:
print("请先生成邮箱地址")
return []
response = self.session.get(f"{self.base_url}/mails")
if response.status_code == 200:
soup = BeautifulSoup(response.text, 'html.parser')
mails = []
for mail in soup.select('.mail-item'):
subject = mail.select_one('.subject').text.strip()
sender = mail.select_one('.sender').text.strip()
time = mail.select_one('.time').text.strip()
mails.append({
'subject': subject,
'sender': sender,
'time': time
})
return mails
return []
# 使用示例
if __name__ == "__main__":
client = NimailClient()
# 生成新邮箱
email = client.generate_email()
# 模拟等待邮件
print("等待邮件中...(模拟场景)")
time.sleep(5)
# 检查邮件
mails = client.check_mails()
print(f"收到 {len(mails)} 封邮件:")
for mail in mails:
print(f"主题: {mail['subject']}, 发件人: {mail['sender']}, 时间: {mail['time']}")