ทำไมต้องทำให้การทดสอบอีเมลเป็นแบบอัตโนมัติ?
การทดสอบระบบยืนยันอีเมลด้วยมือเป็นกระบวนการที่ช้าและมีโอกาสเกิดข้อผิดพลาดสูง คุณต้องสร้างอีเมลใหม่ รอรับจดหมายยืนยัน คลิกลิงก์ แล้วตรวจสอบผลลัพธ์ ทำแบบนี้ซ้ำๆ หลายสิบครั้งต่อ sprint การทำให้เป็นอัตโนมัติช่วยประหยัดเวลาและเพิ่มความน่าเชื่อถือของการทดสอบ
การทดสอบ API ด้วยอีเมลแบบใช้แล้วทิ้ง
EvilMail มี API ที่ช่วยให้คุณสร้างที่อยู่อีเมลแบบใช้แล้วทิ้งและอ่านข้อความที่เข้ามาได้โดยอัตโนมัติ คุณสามารถใช้ API นี้ในสคริปต์ทดสอบเพื่อสร้าง-ยืนยัน-ตรวจสอบวงจรทั้งหมดโดยไม่ต้องแทรกแซงด้วยมือ
ตัวอย่างโค้ด Python
นี่คือตัวอย่างการใช้ Python เพื่อทดสอบการยืนยันอีเมลแบบอัตโนมัติ:
import requests
import time
import re
API_BASE = "https://api.evilmail.com/v1"
API_KEY = "your-api-key-here"
headers = {"Authorization": f"Bearer {API_KEY}"}
# Step 1: Create a disposable address
resp = requests.post(f"{API_BASE}/inboxes", headers=headers)
inbox = resp.json()
email_address = inbox["email"]
# Step 2: Register on the target application
requests.post("https://yourapp.com/register", json={
"email": email_address,
"password": "TestPass123!"
})
# Step 3: Poll for the verification email
for _ in range(30):
time.sleep(2)
msgs = requests.get(
f"{API_BASE}/inboxes/{inbox['id']}/messages",
headers=headers
).json()
if msgs["count"] > 0:
break
# Step 4: Extract and visit the verification link
body = msgs["items"][0]["body"]
link = re.search(r'https://yourapp.com/verify?token=S+', body)
if link:
requests.get(link.group(0))
print("Verification successful!")
