mail.py 544 B

123456789101112131415
  1. from email.mime.multipart import MIMEMultipart
  2. from email.mime.text import MIMEText
  3. from freepost import settings
  4. from subprocess import Popen, PIPE
  5. def send(to_address, subject, body):
  6. email_message = MIMEText(body)
  7. email_message['From'] = settings['email']['from']
  8. email_message['To'] = to_address
  9. email_message['Subject'] = subject
  10. # Open pipe to sendmail
  11. child_process = Popen([ settings['email']['sendmail_path'], "-t" ], stdin=PIPE)
  12. child_process.communicate(email_message.as_bytes())