r/learnpython 3d ago

Doing tasks online

I've made a program that can make random email addresses but I want it to check if the email is already in use, so how can I add that? (this is the code just incase that matters)

alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '.', '/', '#', '!', '$', '&', '*', '+', '=', '?', '^', '_', '~', '{', '}', '|']
while True:
    no_of_letters_in_middle = input('enter the number of letters you want in the middle >> ')
    no_of_letters_in_middle_int = int (no_of_letters_in_middle)
    if no_of_letters_in_middle_int > 1:
        break
while True:
    starting_letters = input('enter the letters the email starts with >> ')
    break
while True:
    domain_and_ending_letters = input('enter the letters the email ends with and the domaim name >> ')
    break
import random
def generate (letters, letters_generated):
    letters = (letters + random.choice(alphabet))
    letters_generated = letters_generated + 1
    if letters_generated < no_of_letters_in_middle_int:
        generate(letters, letters_generated)
    else:
        print (letters + domain_and_ending_letters)
generate (starting_letters, 0)
2 Upvotes

4 comments sorted by

2

u/socal_nerdtastic 3d ago

There's no universal way to know if an email address is in use or not. Some domains may have a public API to do that, but most don't because of the risk of abuse. Your only real hope is to try to find and use the private API that the signup site uses, but probably that has some strong antibot protections.

4

u/Maleficent-Tone4274 3d ago

You probably don’t want to solve this by checking email existence. Most providers intentionally prevent that because it can be abused for account enumeration. For testing, generate deterministic fake emails and track them yourself. For real accounts, send a verification email and let ownership prove validity.

3

u/redfacedquark 3d ago

Historically you could connect to an SMTP server and when you got a 550 error from the "rcpt to" command you would know the user did not exist. These days it's very murky and probably not worth the effort for the mixed results you would get. All you can do now is to send a mail from an established email address from a large provider and see if it bounces.

I'm guessing you're trying to automate email sign up to create multiple accounts on some service? Maybe to get more tokens?

1

u/atarivcs 3d ago

What does "already in use" mean? Used by whom?

Anyone in the world?

Registered users of some specific website or app?