def validate_email(addr):
    """Validate an email address.

    This function raises ``ValueError`` if the email address is not valid.

    >>> validate_email('foo@bar.com')
    'foo@bar.com'
    >>> validate_email('foo@bar com')
    Traceback (most recent call last):
        ...
    ValueError: Invalid domain: bar com

    """
    if '@' not in addr:
        raise ValueError('Invalid email address: %s' % addr)

    node, domain = addr.split('@', 1)
    try:
        domain = idna.encode(force_text(domain))
    except idna.core.IDNAError:
        raise ValueError('Invalid domain: %s' % domain)

    return '%s@%s' % (node, force_text(domain))