AnsweredAssumed Answered

Python email verification?

Question asked by vonmoosa Champion on Aug 20, 2018
Latest reply on Aug 21, 2018 by vonmoosa

Anybody know of a way with Python to get an alert if an email address is invalid?? Below is my current script but I would like to integrate a way to be notified if an email address is invalid and does not get sent. I've read of a way to use server.verify to do this but was unable to get it to work for me.



import arcpy, datetime, smtplib, os, email, email.mime.application 
arcpy.env.overwriteOutput = True

points = r"******************.shp" # feature class
today = # creating date time variable
dte = today.strftime('%m/%d/%Y') # converts date time variable to string
dtep = today.strftime('%m_%d_%Y')

fields = ['Applicant', 'Date_Final', 'Email', 'Permit_No'] # define fields for search cursor and print format to use

arcpy.MakeFeatureLayer_management(points, 'FinalizedApproaches') #makes approaches fc a feature layer for use in this script

with arcpy.da.SearchCursor(points, fields, "Date_Final = CURRENT_DATE") as cursor:
    for row in cursor:
        print "{}\t{}\t{}".format(row[0], " Finalized", row[2])
print " "
print "{} list generated".format(dte)
print " "
print "Finalized notifications are being generated"
print " "

with arcpy.da.SearchCursor(points, fields, "Date_Final = CURRENT_DATE") as email_cursor:
    for row in cursor:
        SERVER = "****************"
        msg = email.mime.Multipart.MIMEMultipart()
        msg['Subject'] = "Test"
        msg['From'] = "***********"
        msg['To'] = "*********"
        msg['Cc'] = "*********"
        msg['Cc2'] = "*********"
        body = email.mime.Text.MIMEText(""'\n {},\n'.format(row[0]) + "        " + "This is to notify you that your approach" + " (" + '{}'.format(row[3]) + ") " + "has been finalized.""")
        att = email.mime.application.MIMEApplication(,_subtype="pdf")
        server = smtplib.SMTP(SERVER)
        server.sendmail('*********', [msg['To'],msg['cc'],msg['Cc2']], msg.as_string())

print "Finalized approach notifications sent."