Exemplo n.º 1
0
    def update(self):
        super(SendNewsletter, self).update()

        if 'form.send' in self.request:
            subs = ISubscribersManagement(self.context.__parent__)

            emails = []
            for principal in subs.getSubscribers():
                mail = IMailAddress(principal, None)
                if mail is not None:
                    email = mail.address

                    if email:
                        emails.append(
                            formataddr((principal.title or principal.id, email)))

            if emails:
                message = self.generateMessage()
                message['Subject'] = make_header(((self.context.title, 'utf-8'),))

                mailer = getUtility(IMailer)

                from_address = str(formataddr(
                    (mailer.email_from_name, mailer.email_from_address)))

                message['From'] = from_address
                mailer.send(from_address, emails, message.as_string())

                IStatusMessage(self.request).add(_('Newsletter has been sent.'))
Exemplo n.º 2
0
    def listSubscribers(self):
        subs = ISubscribersManagement(self.context)

        subscriptions = []
        for principal in subs.getSubscribers():
            mail = IMailAddress(principal, None)
            if mail is not None:
                email = mail.address
            else:
                email = _("Unknown")

            data = {"id": principal.id, "title": principal.title, "email": email}

            subscriptions.append((data["title"], data))

        subscriptions.sort()
        return [data for t, data in subscriptions]