Checking if email is valid
dn
PythonList at DancesWithMice.info
Thu Nov 2 03:11:27 EDT 2023
On 02/11/2023 19.46, Simon Connah via Python-list wrote:
>> On Thu, 2 Nov 2023 at 05:21, Simon Connah via Python-list
>> python-list at python.org wrote:
>>
>
>>> Could someone push me in the right direction please? I just want to find out if a string is a valid email address.
>>
>
>>
>
>> There is only one way to know that a string is a valid email address,
>> and that's to send an email to it.
>>
>
>> What is your goal though? For example, if you're trying to autolink
>> email addresses in text, you don't really care whether it's valid,
>> only that it looks like an address.
>>
>
>
> My goal is to make a simple mailing list platform. I guess I could just send email to an address and if it bounces then I can remove it from the database. Thing is I'm not sure how close to a real email address an email has to be in order to be bounced. If it was completely wrong it might just swallowed up.
Exactly!
Build a complementary script which inspects the returned/bounced
messages, and removes those addresses.
Given that the list of addresses is built from people signing-up in the
first place, one has to presume that people know their own addresses and
can type - there's no real defence against 'stupid'*. It's not as if you
are making-up addresses yourself (in many jurisdictions it is illegal
without opt-in).
An email address: account at domain, has to be accurate in two ways:
1 the domain - otherwise the DNS (Domain Name System) won't be able to
locate the destination email server
2 the account - otherwise the email server won't know to which mail-box
the message should be delivered.
The (1) is why there was some suggestion of using MX records (but may as
well just send the message).
The problem with (2) is that some servers will 'bounce' a message, but
others will let it die silently (not wanting to add to email-spam by
sending stuff 'back' if the message was spam in the first place!)
The exception to (2) is a "catch-all" address, which accepts every
message not addressed to a (legal) mail-box. These are sometimes used to
deal with messages addressed to a staff-member who has left (for
example). However, are somewhat problematic because they pick-up tons of
garbage (eg earlier today I received a message to 456789 at domain.tld.
This is not, and never has been, a mail-box on the domain; but would
drop into a catch-all mail-box.
It would be an unusual MailAdmin inspecting a catch-all address, who
would return a mis-addressed email to its source. If the message was
addressed to Smon at domain.tld, I'd be more likely to assume it was for
you, and forward it to you (in the expectation that you'd fix the
problem with the sender...). However, ...
There are some large businesses doing what you've outlined. They have
not solved this problem - and not through lack of trying!
* as fast as you make something idiot-proof, the world will show you an
'improved' class of idiot!
--
Regards,
=dn
More information about the Python-list
mailing list