You are super. @iCFO I hope you can achieve a successful result.
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!