Il 29/12/2020 02:48, Bischoop ha scritto:
On 2020-12-28, Mats Wichmann <m...@wichmann.us> wrote:
On 12/28/20 10:46 AM, Marco Sulla wrote:
On Mon, 28 Dec 2020 at 17:37, Bischoop <bisch...@vimart.net> wrote:
I'd like to check if there's "@" in a string and wondering if any method
is better/safer than others. I was told on one occasion that I should
use is than ==, so how would be on this example.
s = 't...@mail.is'
You could do simply
if "@" in s:
but probably what you really want is a regular expression.
Will add that Yes, you should always validate your inputs, but No, the
presence of an @ sign in a text string is not sufficient to know it's a
valid email address. Unfortunately validating that is hard.
Nah, by saying if is valid I meant exeactly if there's "@", I could add
yet if endswith() but at this point @ is enough.
Yes the only possible way for full validation would be just sending
email and waiting for reply.
you could try this way:
# -----------
from dns import resolver as dns
emails=['john....@fakeserver.bah',
'john....@gmail.com']
for ue in emails:
try:
mxl = dns.resolve(ue.split('@')[1], 'MX')
except:
print(f'{ue}: bad mail server')
else:
if len(mxl) > 0:
print(f'{ue}: valid mail server')
# -----------
... so, having verified the sever, you should only worry about the name.
--
https://mail.python.org/mailman/listinfo/python-list