code: def sendmail(subject, text, mailto, sender=None):
      
      def user_at_host():
          from socket import gethostname
          return os.getlogin() + "@" + gethostname()
  
      # Body of the message.
      try:
          sender = user_at_host() if sender is None else sender
      except OSError:
          sender = 'abipyscheduler@youknowwhere'
  
      if is_string(mailto): mailto = [mailto]
  
      from email.mime.text import MIMEText
      mail = MIMEText(text)
      mail["Subject"] = subject
      mail["From"] = sender
      mail["To"] = ", ".join(mailto)
  
      msg = mail.as_string()
  
      # sendmail works much better than the python interface.
      # Note that sendmail is available only on Unix-like OS.
      from subprocess import Popen, PIPE
      import sys
  
      sendmail = which("sendmail")
      if sendmail is None: return -1
      if sys.version_info[0] < 3:
          p = Popen([sendmail, "-t"], stdin=PIPE, stderr=PIPE)
      else:
          # msg is string not bytes so must use universal_newlines
          p = Popen([sendmail, "-t"], stdin=PIPE, stderr=PIPE, universal_newlines=True)
  
      outdata, errdata = p.communicate(msg)
      return len(errdata)
docs: Sends an e-mail with unix sendmail.
  
      Args:
          subject: String with the subject of the mail.
          text: String with the body of the mail.
          mailto: String or list of string with the recipients.
          sender: string with the sender address.
              If sender is None, username@hostname is used.
  
      Returns:
          Exit status