how to check if our ip is blacklisted #45

Closed
opened 2021-02-08 08:35:46 +01:00 by manojr2k · 23 comments
manojr2k commented 2021-02-08 08:35:46 +01:00 (Migrated from github.com)

Hi Team

how i can check if my ip is blacklisted for checking email validity?
ii want to grep the response code like 250, 251 , etc in variable ? currently its grepping only True , false and NONE .
how i can achieve that ?

Hi Team how i can check if my ip is blacklisted for checking email validity? ii want to grep the response code like 250, 251 , etc in variable ? currently its grepping only True , false and NONE . how i can achieve that ?
voxvici commented 2021-02-08 09:48:59 +01:00 (Migrated from github.com)

+
Having access to status code and debug object would be nice

`+` Having access to status code and debug object would be nice
manojr2k commented 2021-02-08 10:23:30 +01:00 (Migrated from github.com)

do you know how we can have a access to status code?

do you know how we can have a access to status code?
voxvici commented 2021-02-08 11:26:27 +01:00 (Migrated from github.com)

It's inaccessible from my knowledge. I'll look into making a custom solution because this module isn't production ready

It's inaccessible from my knowledge. I'll look into making a custom solution because this module isn't production ready
reinhard-mueller commented 2021-02-08 11:38:18 +01:00 (Migrated from github.com)

If you use validate_email_or_fail() you should get the exception instead of just False, and if the exception is AddressNotDeliverableError you should get the error messages from the server in the error_messages property.

If you use validate_email_or_fail() you should get the exception instead of just `False`, and if the exception is `AddressNotDeliverableError` you should get the error messages from the server in the `error_messages` property.
manojr2k commented 2021-02-08 11:43:46 +01:00 (Migrated from github.com)

Hi reinhard

thanks for the reply , can you please show some example ? that will be very helpful

Hi reinhard thanks for the reply , can you please show some example ? that will be very helpful
manojr2k commented 2021-02-08 11:49:08 +01:00 (Migrated from github.com)

try:
host = socket.gethostname()
# SMTP lib setup (use debug level for full output)
is_valid = validate_email_or_fail(email_address=abc@abc.com, check_regex=True, check_mx=True, from_address='xyz@gmail.com', helo_host=host, smtp_timeout=10, dns_timeout=10, use_blacklist=False, debug=True)
logger.debug(addressToVerify + " => Response-Code " + str(is_valid))
except Exception:
logger.debug(Exception)

do you mean to say this way ?

try: host = socket.gethostname() # SMTP lib setup (use debug level for full output) is_valid = validate_email_or_fail(email_address=abc@abc.com, check_regex=True, check_mx=True, from_address='xyz@gmail.com', helo_host=host, smtp_timeout=10, dns_timeout=10, use_blacklist=False, debug=True) logger.debug(addressToVerify + " => Response-Code " + str(is_valid)) except Exception: logger.debug(Exception) do you mean to say this way ?
reinhard-mueller commented 2021-02-08 12:08:30 +01:00 (Migrated from github.com)
from validate_email import validate_email_or_fail
from validate_email.exceptions import AddressNotDeliverableError
try:
  validate_email_or_fail("user@domain.org", from_address="myself@gmail.com", helo_host="myhostname")
except AddressNotDeliverableError as e:
  print(e.error_messages)

e.error_messages will be a list of error messages, one for each mail server for the domain. The error messages are strings in the format mail.domain.org.: 550 5.1.1 The email account that you tried to reach does not exist..

```python from validate_email import validate_email_or_fail from validate_email.exceptions import AddressNotDeliverableError try: validate_email_or_fail("user@domain.org", from_address="myself@gmail.com", helo_host="myhostname") except AddressNotDeliverableError as e: print(e.error_messages) ``` `e.error_messages` will be a list of error messages, one for each mail server for the domain. The error messages are strings in the format `mail.domain.org.: 550 5.1.1 The email account that you tried to reach does not exist.`.
manojr2k commented 2021-02-08 12:50:18 +01:00 (Migrated from github.com)

Thanks for the example reinhard

with the code below exceptions are not printing
553 delivery from xx.xxx.xx.xxx is rejected. The connecting IP is blocked using zen.spamhaus.org
550 5.7.606 Access denied, banned sending IP

i can see only below exception is printing
554, b"vastu11.nic.in\nYour access to this mail system has been rejected due to the sending MTA's poor reputation.

Thanks for the example reinhard with the code below exceptions are not printing 553 delivery from xx.xxx.xx.xxx is rejected. The connecting IP is blocked using zen.spamhaus.org 550 5.7.606 Access denied, banned sending IP i can see only below exception is printing 554, b"vastu11.nic.in\\nYour access to this mail system has been rejected due to the sending MTA\'s poor reputation.
karolyi commented 2021-02-08 13:17:01 +01:00 (Migrated from github.com)

@manojr2k the message you see there is what the refusing mail server gives you. you might have more MX records, and one of those is giving you exactly this message.

moreover, another possible scenario is that what you see in your server log differs from what your server shows to the client.

@manojr2k the message you see there is what the refusing mail server gives you. you might have more MX records, and one of those is giving you exactly this message. moreover, another possible scenario is that what you see in your server log differs from what your server shows to the client.
manojr2k commented 2021-02-08 13:23:37 +01:00 (Migrated from github.com)

Hi karolyi

i m trying to check for total 8 email addresses ,and below is the response i am getting
python testcheck.py
m*****@cs.com
ja
.ta@r*****.com
ja**.tripathi@ca
****.co.in
a.5hsd**@*****sd.com
[]
a.***sd@**hs.co.in
[]
a@8gd.co.in
['mailgw.nic.in: (554, b"relayinsp03.nic.in\nYour access to this mail system has been rejected due to the sending MTA's poor reputation.")']
a@545
.co.in
[]
dsa
@***j.com
[]

Hi karolyi i m trying to check for total 8 email addresses ,and below is the response i am getting python testcheck.py m*****@c*******s.com ja****.ta@r*****.com ja**.tripathi@ca*******.co.in a.5hsd**@*****sd.com [] a.***sd@****hs.co.in [] a@**8gd.co.in ['mailgw.nic.in: (554, b"relayinsp03.nic.in\\nYour access to this mail system has been rejected due to the sending MTA\'s poor reputation.")'] a@545***.co.in [] dsa*@***j.com []
karolyi commented 2021-02-08 13:28:24 +01:00 (Migrated from github.com)

it is looking odd, but there can be many reasons this is happening.
you might have dual stack (IPv4/IPv6), you might have various MX servers, or the servers might be set up to reject email checks in a time limited fashion.
all of this is up to your local network situation and the emails you want to check, and thus nothing I can fix (if there is something to fix at all), since it is nothing I can reproduce.

it is looking odd, but there can be many reasons this is happening. you might have dual stack (IPv4/IPv6), you might have various MX servers, or the servers might be set up to reject email checks in a time limited fashion. all of this is up to your local network situation and the emails you want to check, and thus nothing I can fix (if there is something to fix at all), since it is nothing I can reproduce.
reinhard-mueller commented 2021-02-08 13:40:43 +01:00 (Migrated from github.com)

@manojr2k I think a possible reason for this behaviour is that the server does not even wait for the RCPT TO keyword with the recipient email to test, but already closes the connection before that. Can you verify whether that is the case?

@manojr2k I think a possible reason for this behaviour is that the server does not even wait for the `RCPT TO` keyword with the recipient email to test, but already closes the connection before that. Can you verify whether that is the case?
karolyi commented 2021-02-08 13:42:40 +01:00 (Migrated from github.com)

@manojr2k do you get a negative result for a.***sd@**hs.co.in in your example without an exception message?

@manojr2k do you get a negative result for `a.***sd@**hs.co.in` in your example without an exception message?
manojr2k commented 2021-02-08 13:50:12 +01:00 (Migrated from github.com)

if i set debug=True while calling function validate_email_or_fail, i get below output , but print shows only [] in exception, that is what my point is.

23:47:01.934482 send: 'rcpt TO:<a.***sd@**hs.co.in>\r\n'
23:47:01.979897 reply: b'550 5.1.1 <a.***sd@**hs.co.in> User unknown\r\n'
23:47:01.980995 reply: retcode (550); Msg: b'5.1.1 <a.***sd@**hs.co.in> User unknown'
23:47:01.981918 send: 'quit\r\n'
23:47:02.019490 reply: b'221 mx.zoho.in closing connection\r\n'
23:47:02.020116 reply: retcode (221); Msg: b'mx.zoho.in closing connection'

if i set debug=True while calling function validate_email_or_fail, i get below output , but print shows only [] in exception, that is what my point is. 23:47:01.934482 send: 'rcpt TO:<a.***sd@**hs.co.in>\r\n' 23:47:01.979897 reply: b'550 5.1.1 <a.***sd@**hs.co.in> User unknown\r\n' 23:47:01.980995 reply: retcode (550); Msg: b'5.1.1 <a.***sd@**hs.co.in> User unknown' 23:47:01.981918 send: 'quit\r\n' 23:47:02.019490 reply: b'221 mx.zoho.in closing connection\r\n' 23:47:02.020116 reply: retcode (221); Msg: b'mx.zoho.in closing connection'
karolyi commented 2021-02-08 13:51:36 +01:00 (Migrated from github.com)

You should've started with this debug log. As you see from the SMTP converstion, the email is invalid.

What's the issue then? Oh I get it now, sorry, you can't see the response from the server in the exception. I'll look into it.

You should've started with this debug log. As you see from the SMTP converstion, the email is invalid. What's the issue then? Oh I get it now, sorry, you can't see the response from the server in the exception. I'll look into it.
manojr2k commented 2021-02-08 14:01:27 +01:00 (Migrated from github.com)

23:30:12.694727 send: 'rcpt TO:<j123*.tr***@sdsf**-a7**.co.in>\r\n'
23:30:12.721564 reply: b'553 delivery from ...* is rejected. The connecting IP is blocked using zen.spamhaus.org; For further details, please check http://www.spamhaus.org/query/bl?ip=115.96.218.152 and contact zen.spamhaus.org to get the IP De-listed.'
23:30:12.722119 reply: retcode (553); Msg: b'delivery from ...** is rejected. The connecting IP is blocked using zen.spamhaus.org; For further details, please check http://www.spamhaus.org/query/bl?ip=115.96.218.152 and contact zen.spamhaus.org to get the IP De-listed.'
23:30:12.722524 send: 'quit\r\n'

the above is another error which is not getting catch in exception log

23:30:12.694727 send: 'rcpt TO:<j123*.tr***@sdsf**-a7**.co.in>\r\n' 23:30:12.721564 reply: b'553 delivery from ***.**.**.** is rejected. The connecting IP is blocked using zen.spamhaus.org; For further details, please check http://www.spamhaus.org/query/bl?ip=115.96.218.152 and contact zen.spamhaus.org to get the IP De-listed.' 23:30:12.722119 reply: retcode (553); Msg: b'delivery from ***.**.**.*** is rejected. The connecting IP is blocked using zen.spamhaus.org; For further details, please check http://www.spamhaus.org/query/bl?ip=115.96.218.152 and contact zen.spamhaus.org to get the IP De-listed.' 23:30:12.722524 send: 'quit\r\n' the above is another error which is not getting catch in exception log
karolyi commented 2021-02-08 14:03:28 +01:00 (Migrated from github.com)

@manojr2k can you tell me which version of the module you use exactly? these messages should be passed, from the current state of the module. I'm still investigating, but the messages should be passed from what I see now.

@manojr2k can you tell me which version of the module you use exactly? these messages should be passed, from the current state of the module. I'm still investigating, but the messages should be passed from what I see now.
reinhard-mueller commented 2021-02-08 14:05:52 +01:00 (Migrated from github.com)

I think the bug is that _smtp_converse and _check_one_mx add the error message to error_messages for codes between 400 and 499, but for codes 500 and above _smtp_converse just returns None (it falls off the end of the function) and so _check_one_mx doesn't add anything to the error_messages list. This seems to have been introduced in 35efbb7cd9

I think the bug is that `_smtp_converse` and `_check_one_mx` add the error message to `error_messages` for codes between 400 and 499, but for codes 500 and above `_smtp_converse` just returns `None` (it falls off the end of the function) and so `_check_one_mx` doesn't add anything to the `error_messages` list. This seems to have been introduced in 35efbb7cd928d2ba916a2857ed5d5b7fc278d8b8
manojr2k commented 2021-02-08 14:06:13 +01:00 (Migrated from github.com)

py3-validate-email (0.2.12) , this is what i can see for pip3 list py3-validate-email

py3-validate-email (0.2.12) , this is what i can see for pip3 list py3-validate-email
karolyi commented 2021-02-08 14:11:47 +01:00 (Migrated from github.com)

thanks. fixing it now, expect a new version soon.

thanks. fixing it now, expect a new version soon.
manojr2k commented 2021-02-08 14:12:42 +01:00 (Migrated from github.com)

OK great thanks ,

OK great thanks ,
karolyi commented 2021-02-08 14:22:04 +01:00 (Migrated from github.com)

Released 0.2.13, try and test it please.

Released `0.2.13`, try and test it please.
manojr2k commented 2021-02-08 18:05:23 +01:00 (Migrated from github.com)

Hi Karolyi

thanks for the fix ..
now i can see exceptions are getting logged .but just want to know about the format of exception.
you can see Error code 554 is only getting displayed in the log properly. where as in 2nd case mention below , format seems to be not showing error code, can you please comment for the same.

1)Correct format
2021-02-09 03:52:10,145 ["hostmx01.logix.in: (554, b'pune2.logix.in\nIP blacklisted in http://www.senderbase.org')", "hostmx02.logix.in: (554, b'pune2.logix.in\nIP blacklisted in http://www.senderbase.org')"]

2)doubt about the below format
2021-02-09 03:52:04,534 ['mx2.zoho.in: RCPT TO failed: 5.1.1 <a.s*****@.co.in> User unknown', 'mx.zoho.in: RCPT TO failed: 5.1.1 <a.s@.co.in> User unknown', 'mx3.zoho.in: R
CPT TO failed: 5.1.1 <a.s
@*****.co.in> User unknown']

Hi Karolyi thanks for the fix .. now i can see exceptions are getting logged .but just want to know about the format of exception. you can see Error code 554 is only getting displayed in the log properly. where as in 2nd case mention below , format seems to be not showing error code, can you please comment for the same. 1)Correct format 2021-02-09 03:52:10,145 ["hostmx01.logix.in: (554, b'pune2.logix.in\\nIP blacklisted in http://www.senderbase.org')", "hostmx02.logix.in: (554, b'pune2.logix.in\\nIP blacklisted in http://www.senderbase.org')"] 2)**doubt about the below format** 2021-02-09 03:52:04,534 ['mx2.zoho.in: RCPT TO failed: 5.1.1 <a.s*****@*****.co.in> User unknown', 'mx.zoho.in: RCPT TO failed: 5.1.1 <a.s*****@*****.co.in> User unknown', 'mx3.zoho.in: R CPT TO failed: 5.1.1 <a.s*****@*****.co.in> User unknown']
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: karolyi/py3-validate-email#45
No description provided.