Initial import
This commit is contained in:
16
dmarcreceiver/util.py
Normal file
16
dmarcreceiver/util.py
Normal file
@@ -0,0 +1,16 @@
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user