Question: I ' m getting an error code on the fromAddress line. Here's the code I ' m using. I ' m not sure how to
Im getting an error code on the fromAddress line. Here's the code Im using. Im not sure how to fix the issue. Thanks for the help.
import csv
import subprocess
import ezgmail
from ping import ping
# Function to ping an IP address
def pingipip:
try:
result subprocess.runpingn ip captureoutputTrue, textTrue, timeout
if "Request timed out" in result.stdout:
return None
else:
return floatresultstdout.splitAverage splitms
except subprocess.TimeoutExpired:
return None
# Read IP addresses from CSV file
ipFile openipcsv
ipReader csvDictReaderipFile
msg
for row in ipReader:
ip rowip
pingtime pingip
printipt pingtime
# instead of printing the ip and pingtime, how can we
# build a message that contains this info?
#How can we send an email with a message we've built?
# Ping each IP address and store the data
pingdata
for ip in ipFile:
pingresult pingipip
pingdataip pingresult
# Send an email with the ping data
emailcontent
joinfipping for ip ping in pingdata.items
subject "Daily Ping Report"
recipientemail "efincher@mail.pima.edu" # Replace with your email address
ezgmail.inittokenFile"token.json", credentialsFile"credentials.json", fromAddress"efincher@mail.pima.edu"
ezgmail.sendrecipientemail, subject, emailcontent
printEmail sent successfully!"
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
