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!
You probably need to install the package in your python enviroment first
either via conda or via pip
eg
pip install dnspython
br
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.
For starters I can offer this article about how to set up a conda environment and manage it.
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.
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)”
@iCFO That’s a good start! Hope you can test out different domains and TLDs, and then share the workflow
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…
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…
No good news @umutcankurt… While it seems relatively easy to check the email address structure via regex and reliably validate domains, validating individual email addresses within a domain is proving to be quite a challenge. I have tried dozens of different approaches with ChatGPT and all have failed and the same code approaches just get recommended in a cycle. I have had several code iterations that ChatGPT insists are successfully testing the individual email address validity, however it said that most domains block these validity tests so it returns the same results for the entire domain. I even went so far as to send test emails for the validity check. Even with that approach it still couldn’t detect failure other than receiving the standard “Undeliverable:” email in the inbox.
Ultimately ChatGPT continually came back around to recommending a paid API service for validating email addresses, which it caveats by saying that they tend to generate inconsistent results and were more consistent at validating domains. Several had free tiers that handled up to 100 validations.
I will dig back into this every once and a while and see if I can spot anything promising. For now I think that I will take the approach of reading back in the “Undeliverable:” system messages from the sending inbox that occur around bulk report email distributions, then compile a list of the failed email addresses and then have the system email them to the appropriate admin for updating. That doesn’t get ahead of the underlying problem, but it at least provides a way to track and manage emails that require re-sending to new addresses / initiates the correction of distribution list issues.
Here was one of the better python codes if anyone wants to explore a bit. This was my first ever Python interaction, so I am by no means the final word! I pulled out the regex test to isolate during testing, and since that is easy to do with standard nodes within KNIME already. I recommend just creating a temporary email addresses for testing stuff like this you don’t have to sweat security. (this one was “outlook.com” based) Anything reading in BOLD is a comment that has a # in front of it in they python code.
import knime.scripting.io as knio
This example script simply outputs the node’s input table.
knio.output_tables[0] = knio.input_tables[0]
import re
import smtplib
import dns.resolver
SMTP server settings
smtp_server = ‘smtp.office365.com’
smtp_port = 587
smtp_encryption = ‘STARTTLS’
username = ‘EnterYourUserNameHere’
password = ‘EnterYourPasswordHere’
Address used for SMTP MAIL FROM command
fromAddress = ‘EnterSendingEmailAddressHere’
Email address to verify
inputAddress = ‘totallyfakeemailaddress@knime.com’
addressToVerify = str(inputAddress)
Get domain for DNS lookup
splitAddress = addressToVerify.split(‘@’)
domain = str(splitAddress[1])
print(‘Domain:’, domain)
MX record lookup
try:
records = dns.resolver.resolve(domain, ‘MX’)
mxRecord = records[0].exchange
mxRecord = str(mxRecord)
except dns.resolver.NoAnswer:
print(f"No MX records found for {domain}“)
exit(1)
except dns.resolver.NXDOMAIN:
print(f"Domain {domain} does not exist”)
exit(1)
SMTP lib setup (use debug level for full output)
server = smtplib.SMTP(smtp_server, smtp_port)
server.set_debuglevel(0)
SMTP Conversation
server.ehlo() # Identify yourself to the server
server.starttls() # Start a secure connection
server.ehlo() # Re-identify yourself to the server after starting TLS
server.login(‘EnterYourUserNameHere’, ‘EnterYourPasswordHere’) # Login with email credentials
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((inputAddress)+’ - address exists’)
else:
print((inputAddress)+’ - address does not exist’)
@iCFO Really thank you so much. It was a very informative and detailed description of the experience.
I couldn’t be as detailed as you. Therefore, I appreciate it, I will look into this issue from time to time, if there is a valid solution, I will share it. Maybe someone who finds a valid solution will add it as a comment to this post.
Thanks again for all your work.
This turned out to be an amazing project on my end as well. It motivated me to take the leap into Python environments / code and learn to incorporate Chat GPT into my workflow / learn to prompt it more effectively. One better phrased detailed question to GPT-4 got me straight to the answer that this was not really possible at this point. Chat GPT has instantly become part of my workflow and is opening up new opportunities for my company. I am now incorporating it into KNIME to see what it can do with data sets as well. Thanks for the motivation!
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.