Exemplo n.º 1
0
    def _Send(self,
              request,
              response,
              log=None,
              smtp_lib=smtplib.SMTP,
              popen=subprocess.Popen,
              sendmail_command='sendmail'):
        """Implementation of MailServer::Send().

    Logs email message.  Contents of attachments are not shown, only
    their sizes.  If SMTP is configured, will send via SMTP, else
    will use Sendmail if it is installed.

    Args:
      request: The message to send, a mail_service_pb.MailMessage.
      response: An unused api_base_pb.VoidProto.
      log: Log function to send log information.  Used for dependency
        injection.
      smtp_lib: Class of SMTP library.  Used for dependency injection.
      popen2: popen2 function to use for opening pipe to other process.
        Used for dependency injection.
    """
        log = log or self._log_fn

        self._ValidateExtensions(request)
        mime_message = mail.mail_message_to_mime_message(request)
        self._CacheMessage(
            self._email_message_from_mime_message(mime_message, request))
        self._GenerateLog('Send', request, log)

        if self._smtp_host and self._enable_sendmail:
            log('Both SMTP and sendmail are enabled.  Ignoring sendmail.')

        _Base64EncodeAttachments(mime_message)
        if self._smtp_host:

            self._SendSMTP(mime_message, smtp_lib)
        elif self._enable_sendmail:
            self._SendSendmail(mime_message, popen, sendmail_command)
        else:

            logging.info('You are not currently sending out real email.  '
                         'If you have sendmail installed you can use it '
                         'by using the server with --enable_sendmail')
Exemplo n.º 2
0
  def _Send(self, request, response, log=None,
            smtp_lib=smtplib.SMTP,
            popen=subprocess.Popen,
            sendmail_command='sendmail'):
    """Implementation of MailServer::Send().

    Logs email message.  Contents of attachments are not shown, only
    their sizes.  If SMTP is configured, will send via SMTP, else
    will use Sendmail if it is installed.

    Args:
      request: The message to send, a mail_service_pb.MailMessage.
      response: An unused api_base_pb.VoidProto.
      log: Log function to send log information.  Used for dependency
        injection.
      smtp_lib: Class of SMTP library.  Used for dependency injection.
      popen2: popen2 function to use for opening pipe to other process.
        Used for dependency injection.
    """
    log = log or self._log_fn

    self._ValidateExtensions(request)
    mime_message = mail.mail_message_to_mime_message(request)
    self._CacheMessage(
        self._email_message_from_mime_message(mime_message, request))
    self._GenerateLog('Send', request, log)

    if self._smtp_host and self._enable_sendmail:
      log('Both SMTP and sendmail are enabled.  Ignoring sendmail.')

    _Base64EncodeAttachments(mime_message)
    if self._smtp_host:

      self._SendSMTP(mime_message, smtp_lib)
    elif self._enable_sendmail:
      self._SendSendmail(mime_message, popen, sendmail_command)
    else:

      logging.info('You are not currently sending out real email.  '
                   'If you have sendmail installed you can use it '
                   'by using the server with --enable_sendmail')
Exemplo n.º 3
0
    def _SendToAdmins(self, request, response, log=logging.info):
        """Implementation of MailServer::SendToAdmins().

    Logs email message.  Contents of attachments are not shown, only
    their sizes.

    Given the difficulty of determining who the actual sender
    is, Sendmail and SMTP are disabled for this action.

    Args:
      request: The message to send, a mail_service_pb.MailMessage.
      response: An unused api_base_pb.VoidProto.
      log: Log function to send log information.  Used for dependency
        injection.
    """
        self._ValidateExtensions(request)
        mime_message = mail.mail_message_to_mime_message(request)
        self._CacheMessage(mail.AdminEmailMessage(mime_message=mime_message))
        self._GenerateLog('SendToAdmins', request, log)

        if self._smtp_host and self._enable_sendmail:
            log('Both SMTP and sendmail are enabled.  Ignoring sendmail.')
Exemplo n.º 4
0
  def _SendToAdmins(self, request, response, log=None):
    """Implementation of MailServer::SendToAdmins().

    Logs email message.  Contents of attachments are not shown, only
    their sizes.

    Given the difficulty of determining who the actual sender
    is, Sendmail and SMTP are disabled for this action.

    Args:
      request: The message to send, a mail_service_pb.MailMessage.
      response: An unused api_base_pb.VoidProto.
      log: Log function to send log information.  Used for dependency
        injection.
    """
    log = log or self._log_fn

    self._ValidateExtensions(request)
    mime_message = mail.mail_message_to_mime_message(request)
    self._CacheMessage(mail.AdminEmailMessage(mime_message=mime_message))
    self._GenerateLog('SendToAdmins', request, log)

    if self._smtp_host and self._enable_sendmail:
      log('Both SMTP and sendmail are enabled.  Ignoring sendmail.')