17 lines
585 B
Python
17 lines
585 B
Python
import os
|
|
import subprocess
|
|
|
|
def sendmail(msg):
|
|
sendmail_executable = None
|
|
for pth in ( '/usr/sbin', '/usr/bin', '/usr/local/sbin', '/usr/local/bin', '/sbin', '/bin'):
|
|
if os.access(os.path.join(pth, 'sendmail'), os.X_OK):
|
|
sendmail_executable = os.path.join(pth, 'sendmail')
|
|
break
|
|
if sendmail_executable is None:
|
|
raise FileNotFoundError('Could not find sendmail executable')
|
|
|
|
pipe = subprocess.Popen([ sendmail_executable, '-t' ], stdin=subprocess.PIPE)
|
|
stdout, stderr = pipe.communicate(msg.as_bytes)
|
|
return pipe.wait()
|
|
|