Effortlessly validate email addresses with our open-source solution.
Your Email Validator is a lightweight and efficient solution designed to validate email addresses seamlessly. From ensuring proper formatting to checking domain validity, this tool is your go-to for maintaining high-quality data in your applications.
Suggestions, feature requests, and bug reports are always welcome! Head to our Website to learn more or share your feedback.
- Valid Email Format: Ensures the email matches standard email format rules.
- Domain Validation: Checks whether the email domain is valid and reachable.
- Customizable Validation Rules: You can configure additional rules for validation based on your application's requirements.
- Fast and Reliable: Built to be lightweight and optimized for quick validation.
To install the email validator, follow these steps:
-
Clone the Repository:
Clone the repository to your local machine:
git clone https://github.com/tinapyp/YourEmailValidator.git cd YourEmailValidator
-
Install Dependencies:
Install the required dependencies using
pip
:pip install -r requirements.txt
-
Set Up Environment Variables:
Before using the project, you need to configure the necessary environment variables.
- Copy the
.env.example
file to.env
.
cp .env.example .env
- Open the
.env
file and fill in the required fields for the database and email configuration:
# FastAPI Configuration SECRET_KEY=example ACCESS_TOKEN_EXPIRE_MINUTES=30 # Database Configuration MYSQL_USER=example MYSQL_PASSWORD=example MYSQL_HOST=example MYSQL_PORT=example MYSQL_DB=example # Email Configuration SMTP_SERVER=example SMTP_PORT=example LOGIN_EMAIL=example SENDER_EMAIL=example LOGIN_PASSWORD=example
Make sure to replace the
MYSQL_
fields with your actual MySQL database connection details:MYSQL_USER
: Your MySQL usernameMYSQL_PASSWORD
: Your MySQL passwordMYSQL_HOST
: The MySQL server address (e.g.,localhost
or an IP address)MYSQL_PORT
: The port your MySQL server is running on (default is3306
)MYSQL_DB
: The name of the MySQL database you're connecting to
- Copy the
Once the package is installed and the configuration is set, you can easily validate an email address using the following example:
from app.services.email_validator import validate_email
# Example email address
email = "user@example.com"
# Validate the email
is_valid = validate_email(email)
if is_valid:
print("The email is valid!")
else:
print("The email is invalid!")
The validate_email
function checks if the email has a proper format and ensures the domain is reachable.
Here are the available service endpoints for email validation and related functionalities:
This endpoint validates whether a single email address is properly formatted, not disposable, and has valid MX records.
Request:
{
"email": "user@example.com"
}
Response:
{
"valid": true,
"message": "The email is valid."
}
Checks if an email address is from a disposable email provider.
Request:
{
"email": "user@example.com"
}
Response:
{
"valid": true,
"message": "Email is not disposable."
}
Verifies if the domain of the email address has valid MX records.
Request:
{
"email": "user@example.com"
}
Response:
{
"valid": true,
"message": "Email has valid MX records."
}
Validates a list of emails in bulk. Only accessible for DONATUR users.
Request:
{
"email": ["user1@example.com", "user2@example.com"]
}
Response:
[
{
"email": "user1@example.com",
"valid": true,
"message": "The email is valid."
},
{
"email": "user2@example.com",
"valid": false,
"message": "Invalid email format."
}
]
Checks if the current user has access to bulk validation (only DONATUR users have access).
Response:
{
"has_access": true,
"current_status": "DONATUR",
"required_status": "DONATUR",
"upgrade_required": false
}
To upgrade a user to Donatur status, you need to call the /upgrade-to-donatur
endpoint after the user logs in.
In your FastAPI app, uncomment and use the following code:
@router.post("/upgrade-to-donatur", name='upgrade_to_donatur')
async def upgrade_to_donatur(current_user: dict = Depends(get_current_user)):
try:
# Logic to upgrade the user to Donatur status
current_user.status = UserStatus.DONATUR
db.commit()
return RedirectResponse(
url="/dashboard?upgraded=true", status_code=status.HTTP_302_FOUND
)
except Exception as e:
raise HTTPException(status_code=500, detail="Failed to upgrade user status")
Then, update the dashboard.html
page to include a button that triggers this endpoint:
<!-- templates/dashboard.html -->
<a href="{{ url_for('upgrade_to_donatur') }}" class="mt-4">
<button id="upgrade-to-donatur" class="...">Upgrade to Donatur</button>
</a>
To contribute to this project:
- Fork the repository and make changes to your fork.
- Submit a pull request to the main repository once you're done.