Verify an email address with Python
Send a verification code to your own email address, enter it in the terminal and inspect the check result.
1. Prepare the workspace
Create a Bird API key and use an email address you control. Email verification uses the shared Bird Verify sender, so this first test does not require your own sending domain. The first-verification guide covers account setup and channel choices.
2. Install and configure
Use Python 3.10 or later. In a new project directory:
Contoh kode
python3 -m venv .venv
source .venv/bin/activate
python -m pip install messagebird-sdk
export BIRD_API_KEY="YOUR_API_KEY"
export BIRD_TEST_EMAIL="YOUR_EMAIL_ADDRESS"Replace the environment values with your own workspace credentials and test destination. The SDK selects the API region from the key. Run this example on your server or development machine.
3. Run the example
Save as verify.py:
Contoh kode
import os
from bird import Bird
with Bird(api_key=os.environ["BIRD_API_KEY"]) as client:
email = os.environ["BIRD_TEST_EMAIL"]
verification = client.verify.verifications.create(to={"email": email})
print(verification.id, verification.status)
code = input("Enter the code from your email: ").strip()
result = client.verify.verifications.check(to={"email": email}, code=code)
print("Verified:", result.success)Contoh kode
python verify.py4. Inspect the outcome
The first call prints the verification ID and status. After you enter the received code, the check prints whether it succeeded. A delivered code alone does not verify the address; use the check result.
In an application, bind the intended destination and customer action to the server session. The SDK check accepts the destination and code, so do not let an untrusted browser substitute a different destination when checking. Follow signup and recovery for that complete application flow.
Next steps
Sumber daya terkait
Lanjutkan dengan dokumentasi, panduan, dan contoh untuk topik ini. Sumber daya tersedia dalam bahasa Inggris.
Tonton panduannyaVerify phone numbers at signupPahami konsepnyaWhat does OTP mean? One-time passwords explainedJelajahi kemampuannyaCustomer verificationIkuti jalur pembelajaranBuild your first integration
Coba praktiknya dan dapatkan ringkasan implementasi