# call this program with: # echo "blah" | python3 sendAuthMail.py # cat | python3 sendAuthMail.py # python3 sendAuthMail.py 'blah' from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText import smtplib import sys class SendOff(): def __init__(self, message): self.message = message def ignace(self): # Step 2 - Create message object instance msg = MIMEMultipart() smtp_ssl_host = 'mail.mijndomein.nl' # smtp.mail.yahoo.com smtp_ssl_port = 465 # Step 4 - Declare SMTP credentials password = "Cloud%67HgDd4569djs5" username = "cloudserver@suy.nu" sender = 'cloudserver@suy.nu' targets = ['ignace@suy.nu'] # msg = MIMEText('Hi, how are you today?') msg.attach(MIMEText(self.message, 'plain')) msg['Subject'] = "www.suy.nu - system message" msg['From'] = sender msg['To'] = ', '.join(targets) server = smtplib.SMTP_SSL(smtp_ssl_host, smtp_ssl_port) server.login(username, password) server.sendmail(sender, targets, msg.as_string()) server.quit() if __name__ == "__main__": body = '' if len(sys.argv) > 1: body = sys.argv[1] else: for line in sys.stdin: body += line if len(body) > 0: s = SendOff(body) s.ignace()