add a simple interface function
This commit is contained in:
+9
-2
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user