Hello,

I was looking for a way to have time limited email addresses on Uberspace. This can easily be implemented but you cannot reject emails then they are transmitted to the email server, only after they have already been received. Hence, even if you do not see them, spam needs to be processed.

To circumvent this problem, I wrote a python script which will create .qmail files so the mail server knows which address to reject and which not. After some time has passed (in my case, I chose 1 day), the script will remove these files and replace them with new ones.

The script is called via cron once a day.

Here is my script:

temp_addr.py

#!/usr/bin/env python3.4

import os
import datetime

today = datetime.date.today()
qmail_dir = None #add user dir here

today = datetime.datetime.now()
yesterday = today - datetime.timedelta( days = 1 )
tomorrow = today + datetime.timedelta( days = 1)

valid_addresses = [".qmail-temp-" + x.strftime('%d-%m') for x in (tomorrow, today, yesterday)]

for file in os.listdir(qmail_dir):
    if file.startswith(".qmail-temp-"):
        if not file in valid_addresses:
            os.unlink(os.path.join(qmail_dir, file))
        else:
            valid_addresses.remove(file)

for addr in valid_addresses:
    os.symlink(os.path.join(qmail_dir, ".temp_mail_addr"), os.path.join(qmail_dir, addr))

With this script running once a day, you have three email addresses which are valid at the same time. All three email addressses will be handled by the .temp_mail_addr file.

Now you only have to include these temporal email addresses on your homepage. I chose to use JavaScript for this.

<h2>EMail:</h2>
<script type="text/javascript">
    var currentDate = new Date();
    var day = currentDate.getDate();
    var month = currentDate.getMonth() + 1;
    var year = currentDate.getFullYear();
    if(month <= 9)
        month = '0'+month;
    if(day <= 9)
        day = '0'+day;
    var mail = "temp-" + day + "-" + month  + "@flambda.de";
    document.write("<a href='mailto:" + mail + "'>" + mail + "</a>");
</script>

Check my impressum for a live demo: Impressum

If now a crawler sees this temporal email address, it can only sent you spam for a maximum of 2 days. You could also cut down on this time frame by making the addresses hour based but for me, this was enough to remove all spam on these addresses.


Published

Category

misc

Tags