Checking the correctness of the e-mail address. whether it is valid

Hi;
I have more than 150 e-mail addresses in my list. Before sending e-mails, I need to find which ones are active and which ones are inactive. I wonder if it is possible to convert it to a node or workflow with the code in the link? or e-mail addresses in excel list

  • Detection of spelling errors of the e-mail address
  • Checking if e-mail addresses are still valid, I don’t want to send e-mails to e-mail addresses that no longer work.
import re
import smtplib
import dns.resolver

# Address used for SMTP MAIL FROM command.
fromAddress = 'test@example.com'

# Simple Regex for syntax checking
regex = '^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$'

# Email address to verify
inputAddress = input('Please enter the emailAddress to verify:')
addressToVerify = str(inputAddress)

# Syntax check
match = re.match(regex, addressToVerify)
if match == None:
   print('Bad Syntax')
   raise ValueError('Bad Syntax')

# Get domain for DNS lookup
splitAddress = addressToVerify.split('@')
domain = str(splitAddress[1])
print('Domain:', domain)

# MX record lookup
records = dns.resolver.query(domain, 'MX')
mxRecord = records[0].exchange
mxRecord = str(mxRecord)


# SMTP lib setup (use debug level for full output)
server = smtplib.SMTP()
server.set_debuglevel(0)

# SMTP Conversation
server.connect(mxRecord)
server.helo(server.local_hostname) ### server.local_hostname(Get local server hostname)
server.mail(fromAddress)
code, message = server.rcpt(str(addressToVerify))
server.quit()

#print(code)
#print(message)

# Assume SMTP response 250 is success
if code == 250:
   print('Success')
else:
   print('Bad')
2 Likes

The regex test is super easy without any custom node development. An email address validity test would be a really nice addition to KNIME! I think that this might be possible as a relatively simple component using existing nodes, but I have never tried to look up mx records for a domain via KNIME so I can’t guarantee it.

Maybe one of the heavier web developer users could help with a jumpstart on mx record lookups. The Java Snippet node might be able to do it on its own.

1 Like

Thanks for the answer.
We have done it before with vba macro where I found the translation node with dear Armin. If we can make this node to control it would be functional for many people. Because finding out if e-mail addresses are valid is simple but really important.

People leaving jobs, people changing companies… and lots of junk email addresses. This is a critical need to get rid of junk mail that you can’t deliver. I hope someone can help with the solution with this example I shared.
Checking the spelling or format of the e-mail address is simple. The main thing is that I still have an active e-mail address? / Or is it an invalid e-mail address now?

1 Like

I would use it every time before distributing reports by email or updating row level user security tables. There is always a lag on entering user changes when dealing with organizations with heavy turnover, but they are typically quick to disable email addresses. This test would get ahead of issues and avoid a lot of distribution corrections on my end.

1 Like

Does anyone have a suggestion? Or any suggestions for a solution?

copy paste the code into a python script node
br

yes i tried that but i didn’t succeed because i didn’t work with python before. So I needed more professional help to get it working. In fact, if it can be turned into a node, it will work for many people, it will be beneficial for the community.

:13: DeprecationWarning: invalid escape sequence .
Executing the Python script failed: Traceback (most recent call last):
File “”, line 7, in
ModuleNotFoundError: No module named ‘dns’

Also not a python guy unfortunately… Would this module require the manual installation of another Python environment perhaps? I read that this was fixed for a few people by moving to Python 3 on a Stack Overflow thread…

@mlauber71 is a heavy python user. Maybe he will find us and offer some python tips!

1 Like

Thanks for testing and reporting results. @iCFO

You probably need to install the package in your python enviroment first
either via conda or via pip
eg
pip install dnspython
br

1 Like

I really don’t know how to do it. I installed both and updated my knime. I looked at the directions, I couldn’t do something because I didn’t know. I hope you understand that before posting here, I actually tried it myself. :frowning:
image
image

For starters I can offer this article about how to set up a conda environment and manage it.

3 Likes

Thanks for the reply. @mlauber71
It’s a good guide, I’ll try, but I’m using windows. Will I see?

It is also for Windows and after installing Miniforge it will work basically the same on every operating system. You could first check if the bundled Python version is enough then you will not need conda, but it might be that you need additional packages.

I was able to get Anaconda installed with the necessary packages in a KNIME acceptable environment. Here is what worked for me in Windows 11:

Install Anaconda - Anaconda | Anaconda Distribution

Open Anaconda Navigator - Click on green arrow next to “base (root)” and hit “Open Terminal”, paste in “conda install conda==4.14” and hit enter.
(info from this forum post - Unable to integrate python with Knime - #2 by steffen_KNIME)

Install OpenSSL - Win32/Win64 OpenSSL Installer for Windows - Shining Light Productions

KNIME Preferences / KNIME / Conda - (set path to) C:\ProgramData\Anaconda3

KNIME Preferences / KNIME / Python - Set to Conda, then hit “New evironment…” I named mine “py39_knime” to mirror @mlauber71

KNIME Preferences / KNIME / Python - Set to Manual, and select your conda environment exe file “C:\Users\iCFO.conda\envs\py39_knime\python.exe” (replace “iCFO” with your windows user name)

Open Anaconda Navigator - Click on green arrow next to “py39_knime” and hit “Open Terminal”, paste in “conda install -c conda-forge dnspython” and hit enter.
(Info for this step was found here: :: Anaconda.org)

The python code is not fully working yet, but I will split that into another post.

2 Likes

import re
import smtplib
import dns.resolver

Address used for SMTP MAIL FROM command.

fromAddress = ‘test@example.com’

Simple Regex for syntax checking

regex = ‘^[_a-z0-9-]+(\.[_a-z0-9-]+)@[a-z0-9-]+(\.[a-z0-9-]+)(\.[a-z]{2,})$’

Email address to verify

inputAddress = ‘name@domain-you-want-to-test.com’
addressToVerify = str(inputAddress)

Syntax check

match = re.match(regex, addressToVerify)
if match == None:
print(‘Bad Syntax’)
raise ValueError(‘Bad Syntax’)

Get domain for DNS lookup

splitAddress = addressToVerify.split(‘@’)
domain = str(splitAddress[1])
print(‘Domain:’, domain)

MX record lookup

records = dns.resolver.resolve(domain, ‘MX’)
mxRecord = records[0].exchange
mxRecord = str(mxRecord)

SMTP lib setup (use debug level for full output)

server = smtplib.SMTP()
server.set_debuglevel(0)

SMTP Conversation

server.connect(mxRecord)
server.helo(server.local_hostname) ### server.local_hostname(Get local server hostname)
server.mail(fromAddress)
code, message = server.rcpt(str(addressToVerify))
server.quit()

#print(code)
#print(message)

Assume SMTP response 250 is success

if code == 250:
print(‘Success’)
else:
print(‘Bad’)

Results…

Executing the Python script failed: Traceback (most recent call last):
File “”, line 37, in
File “C:\Users\iCFO.conda\envs\py39_knime\lib\smtplib.py”, line 341, in connect
self.sock = self._get_socket(host, port, self.timeout)
File “C:\Users\iCFO.conda\envs\py39_knime\lib\smtplib.py”, line 312, in _get_socket
return socket.create_connection((host, port), timeout,
File “C:\Users\iCFO.conda\envs\py39_knime\lib\socket.py”, line 844, in create_connection
raise err
File “C:\Users\iCFO.conda\envs\py39_knime\lib\socket.py”, line 832, in create_connection
sock.connect(sa)
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

FYI - The line 37 error aligns with “server.connect(mxRecord)”

3 Likes

@iCFO That’s a good start! Hope you can test out different domains and TLDs, and then share the workflow :slight_smile:

2 Likes

I will try increasing the timeout setting in the KNIME.ini file first tomorrow by adding:

-Dknime.python.connecttimeout=30000

If that doesn’t work, then I will probably try some firewall and antivirus troubleshooting… :crossed_fingers:

Any luck on the Anaconda Python Environment on your end @umutcankurt?

@iCFO
I haven’t done it yet because I didn’t have time because of my other jobs. You’re ahead of me on this one. If you get a positive result, please share

With the help of ChatGPT, I was able to modify the code and get it to connecting to an email server that performs the test / then attempts to verify a single email address. Unfortunately at this point it verifies any email at an existing domain as “Success”. Trying some alternate approaches…

4 Likes