AnsweredAssumed Answered

attach txt file to email...

Question asked by jay.kapalczynski on Nov 21, 2016
Latest reply on Nov 21, 2016 by dkwiens

I am trying to attach a txt file to my email I am creating in python.  Anyone know how I can attach a txt file to the email?

 

#....snip

outFile = open(r"C:\Users\\TestFile.text", "w")

# return all rows
with arcpy.da.SearchCursor(fc, ['*'], where_clause=expression) as cursor:
# return specific rows
#with arcpy.da.SearchCursor(fc, [class_field, name_field], where_clause=expression) as cursor:

    for row in cursor:
        ## Print the name of the residential road
        #print('{0}, {1}'.format(row[0], row[1]))
        print(row)
        zval = str('{0}, {1}'.format(row[0], row[1]))
        outFile.write(zval + "\n")


outFile.close()      

#===SET EMAIL To AND From==============================
FROMADDR = "me@somewherea.gov"
TOADDRS  = ["me@somewherea.gov"]

#===BUILD EMAIL========================================
def msgEmail():
    msg = "Test"
    server = smtplib.SMTP('smtp0.sitevision.com',25)
    server.set_debuglevel(1)
    server.ehlo()
    server.sendmail(FROMADDR, TOADDRS, msg)
    server.quit()
    return "Email Sent but Import Aborted"

#===PROCESS EMAIL======================================
getMsgP = msgEmail()
print getMsgP

Outcomes