Overview
Extracting a domain name from an email address is a common requirement in data processing and integration workflows. This process separates the domain portion from the user identifier using string manipulation.
In eZintegrations, Python Operations can be used to extract the domain name from incoming email data using the split function.
When to Use
Use this method when you need to identify or process the company domain from user email addresses.
- Mapping users to organizations
- Validating corporate email domains
- Automating company identification
- Enriching integration workflows
- Processing user profile data
How It Works
The email address is split at the @ symbol using Pythonโs split() function. The portion after the symbol represents the domain name.
This extracted domain is then added to the outgoing JSON response for use in downstream processes.
Incoming JSON Data
The Python Operation receives email information in JSON format as input.
{
"email": "info@bizdata360.com"
}
Python Operation Logic
The following Python script retrieves the email value, extracts the domain using the split function, and prepares the output response.
# Sending to input of operation
Responsedata = []
# Extract the value of the "email" key
email_value = pycode_data.get("email", "") # Default to empty string if missing
def extract_domain(email):
# Split the email at '@' and get the domain part
domain = email.split('@')[-1].strip()
return domain
# Extract the domain
domain = extract_domain(email_value)
# Prepare the response as JSON
response = {
"companyDomain": domain # Domain name (e.g., bizdata360.com)
}
# Sending to output of operation
pycode_data.update(response)
Outgoing Data
After processing, the Python Operation returns the original email and the extracted domain name.
{
"email": "info@bizdata360.com",
"companyDomain": "bizdata360.com"
}
How to Use
Follow these steps to extract the domain name using Python Operations.
- Configure the integration to receive email data in JSON format.
- Open the Python Operation editor.
- Paste the domain extraction script.
- Ensure the input variable contains the email key.
- Save and deploy the workflow.
- Test the operation with sample input.
Use Case Example
This method can be used to automatically associate users with their organizations based on email domain.
- Email: user@company.com
- Extracted Domain: company.com
- Mapped Organization: Company
Troubleshooting
- Verify that the input JSON contains the email field.
- Ensure the email format includes the @ symbol.
- Check for empty or null email values.
- Confirm that pycode_data is properly initialized.
- Review logs if the output is missing the domain field.
Frequently Asked Questions
What does the split function do in this example?
The split function separates the email string at the @ symbol and returns the domain portion.
What happens if the email field is missing?
The script assigns an empty string as the default value, preventing runtime errors.
Can this method work with multiple emails?
This implementation processes one email value at a time. Multiple emails require looping logic.
Why is strip() used after splitting?
The strip() method removes extra spaces that may appear before or after the domain value.
Is this method case-sensitive?
The extraction preserves the original case of the domain as provided in the input.
Notes
- This method assumes valid email formatting.
- Additional validation may be required for untrusted inputs.
- Store extracted domains securely when used in workflows.
- Use consistent naming conventions for output fields.