[smartmontools-support] Contribution to: /usr/share/doc/smartmontools/examples

Tony Tortorelli tonyt at att.net
Sun Mar 19 15:47:24 CET 2023


I'm using a headless Raspberry Pi.  The standard distribution of Pi OS Lite does not include mail or sendmail, so I used the python email package to create this script.
My example below uses a Gmail account to as an argument to the -M exec Directive in /etc/smartd.conf

Maybe this will be useful for your Examples in /usr/share/doc/smartmontools/examples:

#!/usr/bin/python
#
# This is a Python Email script using the python email package
# See: https://docs.python.org/3/library/email.examples.html
# May be useful if there is no other mail(1) compatible mailer
# available.
# This example requires a GMail Account
# Requied:  gmail adddredd and password
# Optional: fromname, toname
#

import os
import smtplib
import mimetypes
from email.message import EmailMessage

fromname = 'My Name'
fromaddr = 'myaddress at gmail.com'
password = 'GmailPassword'
toname = 'To Name'
toaddr =  os.getenv('SMARTD_ADDRESS').replace(" ", ",")
subject = os.getenv('SMARTD_SUBJECT')
message = os.getenv('SMARTD_FULLMESSAGE')

msg = EmailMessage()
msg.set_content(message, 'html')
msg['Subject'] = subject
msg['From'] = "%s <%s>" % (fromname, fromaddr)
msg['To'] = "%s <%s>" % (toname, toaddr)

server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(fromaddr, password)
server.send_message(msg)
server.quit()




More information about the Smartmontools-support mailing list