From 2cdc67f4afcae58e2b2ac2a6b96a6595866e828e Mon Sep 17 00:00:00 2001 From: Sven Augustin Date: Tue, 15 Feb 2022 11:59:14 +0100 Subject: [PATCH] add a simple interface function --- sendmail.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sendmail.py b/sendmail.py index 383fd50..a2f8c41 100644 --- a/sendmail.py +++ b/sendmail.py @@ -7,6 +7,13 @@ OUTPUT_DIVIDER = "The message was:" OUTPUT_DIVIDER_BAR = "=" * len(OUTPUT_DIVIDER) +def sendmail(to_addr, from_addr=None, subject=None, body=None): + msg = SendMailMessage(to_addr, from_addr=from_addr, subject=subject, body=body) + msg.send() + return msg + + + class SendMailMessage: def __init__(self, to_addr, from_addr=None, subject=None, body=None): @@ -17,7 +24,7 @@ class SendMailMessage: def send(self): msg = self.encode() - sendmail(msg) + _run_sendmail(msg) def encode(self, *args, **kwargs): @@ -37,7 +44,7 @@ class SendMailMessage: -def sendmail(msg): +def _run_sendmail(msg): cmd = ("sendmail", "-t", "-oi") res = subprocess.run(cmd, input=msg, stderr=subprocess.PIPE) try: