Search code examples
email-address

alter email address in DB to render it un-deliverable


I need to alter email addresses of users to render them undeliverable (not ever a real address), however it needs to be reversible so that the original is visible or at least retrievable (without storing it elsewhere).

For example [email protected] -> [email protected] might work as it can be changed back. However, the problem is that I cannot KNOW that the above-resulting address is not a real email address. Maybe there is a real address out there called [email protected].

The requirements are that the address needs to be valid (in terms of having '@' and '.com' etc) but won't send.

Maybe my requirements are a contradiction and hence not possible? Does anyone know?


Solution

  • Your requirements are kind of a contradiction. The only way to make an addres unworkable is to render it practically invalid.

    Note that "invalid" can mean at least three things;

    1. it doesn't parse as an e-mail address (e.g. replace @ by ⓐ)
    2. the user name is invalid at that domain
    3. the domain name is invalid

    The point is that for 2 and 3 there is no easy way to know for sure if that is the case.


    What you also could do is obfuscate the e-mail addres by applying a reversable transformation, like e.g. base64 encoding it. This falls under category 1 above.

    For example in Python 3:

    In [1]: import base64 
    
    In [2]: base64.b64encode('[email protected]'.encode('utf-8')) 
    Out[2]: b'am9obkBleGFtcGxlLmNvbQ=='
    
    In [3]: base64.b64decode(b'am9obkBleGFtcGxlLmNvbQ==').decode('utf-8') 
    Out[3]: '[email protected]'