def createMessage(self):
     """Generate a basic message, MailBoxer will take care of all the
        important headers, hopefully."""
     headers = {'Message-Id': self.new_message_id(),
                'Date': self.rfc_date(),}
     ml = self.getMailingList()
     encoding = getSiteEncoding(ml)
     body = decode(self.request.get('body'), ml)
     subject = decode(self.request.get('subject'), ml)
     message = construct_simple_encoded_message(from_addr=self.member_address(),
                                                to_addr=self.list_address(),
                                                subject=subject,
                                                body=body,
                                                other_headers=headers,
                                                encoding=encoding)
     return message.as_string()
 def createMessage(self):
     """Generate a basic message, MailBoxer will take care of all the
        important headers, hopefully."""
     headers = {
         'Message-Id': self.new_message_id(),
         'Date': self.rfc_date(),
     }
     ml = self.getMailingList()
     encoding = getSiteEncoding(ml)
     body = decode(self.request.get('body'), ml)
     subject = decode(self.request.get('subject'), ml)
     message = construct_simple_encoded_message(
         from_addr=self.member_address(),
         to_addr=self.list_address(),
         subject=subject,
         body=body,
         other_headers=headers,
         encoding=encoding)
     return message.as_string()
    def sendCommandRequestMail(self, address, subject, body, from_address=None, extra_headers={}):
        if not address: 
            print ('Products.listen.content.MailBoxerMailingList.sendCommandRequestMail() '
                   'invalid address; user may have been deleted')
            return

        if from_address is None:
            from_address = self.mailto

        # Default headers:
        headers = {'X-Mailer': self.getValueFor('xmailer')}
        headers.update(extra_headers)
        encoding = getSiteEncoding(self)
        message = construct_simple_encoded_message(from_addr=from_address,
                                                   to_addr=address,
                                                   subject=subject,
                                                   body=body,
                                                   other_headers=headers,
                                                   encoding=encoding)
            
        # XXX: Acquire the MailHost, yuck
        mh = getToolByName(self, 'MailHost')
        mh.send(str(message))
예제 #4
0
    def sendCommandRequestMail(self, address, subject, body, from_address=None, extra_headers={}):
        if not address: 
            print ('Products.listen.content.MailBoxerMailingList.sendCommandRequestMail() '
                   'invalid address; user may have been deleted')
            return

        if from_address is None:
            from_address = self.mailto

        # Default headers:
        headers = {'X-Mailer': self.getValueFor('xmailer')}
        headers.update(extra_headers)
        encoding = getSiteEncoding(self)
        message = construct_simple_encoded_message(from_addr=from_address,
                                                   to_addr=address,
                                                   subject=subject,
                                                   body=body,
                                                   other_headers=headers,
                                                   encoding=encoding)
            
        # XXX: Acquire the MailHost, yuck
        mh = getToolByName(self, 'MailHost')
        mh.send(str(message))
예제 #5
0
    def sendMail(self, mto, msg=None, subject=None,
                 mfrom=None, **kwargs):
        """
        Send a message.
         mto - an email address or list of email addresses.
         msg - a message string or Message instance.
               (If you have a msgid, use constructMailMessage() first.
         subject - a subject string or Message instance.
         mfrom - the sender's email address.

         Any remaining keyword args are used for interpolation when
         translating the message.
        """
        # insert the portal title, used by nearly every message,
        # including those that don't come from constructMailMessage().
        # fixes bug #1711.
        kwargs.setdefault('portal_title', self.context.Title())
        if isinstance(msg, Message):
            msg = self._translate(msg, mapping=kwargs)
        if isinstance(subject, Message):
            subject = self._translate(subject, mapping=kwargs)
        if type(mto) in StringTypes:
            mto = (mto,)
        recips = []
        for recip in mto:
            recip = self._to_email_address(recip)
            # prevent None's from getting added (maybe only test
            # environ case, but the admin users have no emails)
            if recip:
                recips.append(recip)

        # XXX Validate that there's at least one recip??

        if mfrom is None:
            mfrom = self.context.getProperty('email_from_address')
        else:
            email_addr = self._to_email_address(mfrom)
            # if mfrom doesn't look like a valid email address
            # and is not a userid, we return none back
            # this happens for addresses like anonymous@nohost
            # which occurs during unit tests
            # we leave the mfrom alone in that case
            if email_addr is not None:
                mfrom = email_addr
        
        #we construct the mail message ourselves ... because the mailhost generates bogus messages
        #by bogus i mean that the mail message generated has 2 sets of separate headers
        mapping = self._unicode_values(dict(
            from_addr=mfrom,
            to_addr='; '.join(recips),
            subject=subject,
            body=msg,
            ))
        if subject:
            msg = u"""\
From: %(from_addr)s
To: %(to_addr)s
Subject: %(subject)s

%(body)s""" % mapping
        else:
            msg = u"""\
From: %(from_addr)s
To: %(to_addr)s
%(body)s""" % mapping

        # At this point we should have a unicode string; we need raw
        # bytes to send, and we need to do the weird quoted-printable
        # encoding of non-ascii strings.
        try:
            msg = msg.encode('ascii')
        except UnicodeEncodeError:
            mapping['encoding'] = self._encoding

            # see http://trac.openplans.org/openplans/ticket/2808
            # it looks like construct_simple_encoded_message ought
            # to be doing this itself, but the line is commented
            # out there, so i'll be cautious and make the most
            # minimally-invasive change possible. this should
            # probably be investigated upstream in listen and
            # (hopefully) this line eventually removed.
            mapping['body'] = body_encode(mapping['body'])

            msg = str(construct_simple_encoded_message(**mapping))

        self._send(msg)