May-22-2018, 06:30 PM
Hello,
I created the following function to return the results of Linux mounts points with over a certain percentage of used space:
Here is the email code:
I created the following function to return the results of Linux mounts points with over a certain percentage of used space:
>>> def mounts(): ... devs = psutil.disk_partitions() ... for dev in devs: ... part = int(psutil.disk_usage(dev.mountpoint).percent) ... if part > 60: ... print(dev.mountpoint, part) ... >>> mounts() /var 71 /u01 61 /backups 69I'd like to email the output above. However, when I attempt to email the output I receive nothing in the body.
Here is the email code:
>>> import smtplib >>> mail_server = 'localhost' >>> mail_server_port = 25 >>> from_addr = 'test@domain' >>> to_addr = 'email@domain' >>> from_header = 'From: %s\r\n' % from_addr >>> to_header = 'To: %s\r\n\r\n' % to_addr >>> subject_header = 'Subject: TEST' >>> body = mounts() /var 71 /u01 61 /backups 69 >>> email_message = '%s' % body >>> s = smtplib.SMTP(mail_server, mail_server_port) >>> s.sendmail(from_addr, to_addr, email_message) {} >>> s.quit()Any idea why the body of the email is empty?