Random Email Generator

  • Share this:

Code introduction


The function accepts a username and a domain as parameters, uses the Person module of the Mimesis library to generate a random username and domain, and then combines them to create a random email address.


Technology Stack : Mimesis library

Code Type : Function

Code Difficulty : Intermediate


                
                    
def generate_random_email(user, domain):
    """
    Generates a random email address.

    Parameters:
    user (str): The username part of the email.
    domain (str): The domain part of the email.

    Returns:
    str: A randomly generated email address.
    """
    import random
    import mimesis

    # Generate a random username and domain
    username = mimesis Person().email().username()
    domain = mimesis Person().email().domain()

    # Combine the username and domain to create an email address
    email = f"{username}@{domain}"

    return email