Exemple #1
0
def to_mail(to_name, to_email, subject, body, headers={}, decorate_body=True):
    try:
        email_from = config.get("adhocracy.email.from")

        if decorate_body:
            body = (
                _(u"Hi %s,") % to_name
                + u"\r\n\r\n%s\r\n\r\n" % body
                + _(u"Cheers,\r\n\r\n" u"    the %s Team\r\n") % config.get("adhocracy.site.name")
            )

        msg = MIMEText(body.encode(ENCODING), "plain", ENCODING)

        for k, v in headers.items():
            msg[k] = v

        subject = Header(subject.encode(ENCODING), ENCODING)
        msg["Subject"] = subject
        msg["From"] = _("%s <%s>") % (config.get("adhocracy.site.name"), email_from)
        to = Header(u"%s <%s>" % (to_name, to_email), ENCODING)
        msg["To"] = to
        msg["Date"] = email.Utils.formatdate(time())
        msg["X-Mailer"] = "Adhocracy SMTP %s" % version.get_version()
        # log.debug("MAIL\r\n" + msg.as_string())
        send(email_from, to_email, msg.as_string())
    except Exception:
        log.exception("Sending mail failed.")
Exemple #2
0
def to_mail(to_name, to_email, subject, body, headers={}, decorate_body=True,
            email_from=None, name_from=None):
    try:
        if email_from is None:
            email_from = config.get('adhocracy.email.from')
        if name_from is None:
            name_from = config.get('adhocracy.site.name')

        if decorate_body:
            body = (_(u"Hi %s,") % to_name +
                    u"\r\n\r\n%s\r\n\r\n" % body +
                    _(u"Cheers,\r\n\r\n"
                      u"    the %s Team\r\n") %
                    config.get('adhocracy.site.name'))

        # wrap body, but leave long words (e.g. links) intact
        body = u'\n'.join(textwrap.fill(line, break_long_words=False)
                          for line in body.split(u'\n'))

        msg = MIMEText(body.encode(ENCODING), 'plain', ENCODING)

        for k, v in headers.items():
            msg[k] = v

        subject = Header(subject.encode(ENCODING), ENCODING)
        msg['Subject'] = subject
        msg['From'] = _("%s <%s>") % (name_from, email_from)
        to = Header(u"%s <%s>" % (to_name, to_email), ENCODING)
        msg['To'] = to
        msg['Date'] = email.Utils.formatdate(time())
        msg['X-Mailer'] = "Adhocracy SMTP %s" % version.get_version()
        #log.debug("MAIL\r\n" + msg.as_string())
        send(email_from, to_email, msg.as_string())
    except Exception:
        log.exception("Sending mail failed.")
Exemple #3
0
def to_mail(to_name, to_email, subject, body, headers={}, decorate_body=True):
    try:
        email_from = config.get('adhocracy.email.from')

        if decorate_body:
            body = (
                _(u"Hi %s,") % to_name + u"\r\n\r\n%s\r\n\r\n" % body +
                _(u"Cheers,\r\n\r\n"
                  u"    the %s Team\r\n") % config.get('adhocracy.site.name'))

        msg = MIMEText(body.encode(ENCODING), 'plain', ENCODING)

        for k, v in headers.items():
            msg[k] = v

        subject = Header(subject.encode(ENCODING), ENCODING)
        msg['Subject'] = subject
        msg['From'] = _("%s <%s>") % (config.get('adhocracy.site.name'),
                                      email_from)
        to = Header(u"%s <%s>" % (to_name, to_email), ENCODING)
        msg['To'] = to
        msg['Date'] = email.Utils.formatdate(time())
        msg['X-Mailer'] = "Adhocracy SMTP %s" % version.get_version()
        #log.debug("MAIL\r\n" + msg.as_string())
        send(email_from, to_email, msg.as_string())
    except Exception:
        log.exception("Sending mail failed.")
Exemple #4
0
def to_mail(to_name, to_email, subject, body, headers={}, decorate_body=True,
            email_from=None, name_from=None):
    try:
        if email_from is None:
            email_from = config.get('adhocracy.email.from')
        if name_from is None:
            name_from = config.get('adhocracy.site.name')

        if decorate_body:
            body = (_(u"Hi %s,") % to_name +
                    u"\r\n\r\n%s\r\n\r\n" % body +
                    _(u"Cheers,\r\n\r\n"
                      u"    the %s Team\r\n") %
                    config.get('adhocracy.site.name'))

        msg = MIMEText(body.encode(ENCODING), 'plain', ENCODING)

        for k, v in headers.items():
            msg[k] = v

        subject = Header(subject.encode(ENCODING), ENCODING)
        msg['Subject'] = subject
        msg['From'] = _("%s <%s>") % (name_from, email_from)
        to = Header(u"%s <%s>" % (to_name, to_email), ENCODING)
        msg['To'] = to
        msg['Date'] = email.Utils.formatdate(time())
        msg['X-Mailer'] = "Adhocracy SMTP %s" % version.get_version()
        #log.debug("MAIL\r\n" + msg.as_string())
        send(email_from, to_email, msg.as_string())
    except Exception:
        log.exception("Sending mail failed.")
Exemple #5
0
def to_mail(
    to_name, to_email, subject, body, headers={}, decorate_body=True, email_from=None, reply_to=None, name_from=None
):
    try:
        if email_from is None:
            email_from = config.get("adhocracy.email.from")
        if name_from is None:
            name_from = config.get("adhocracy.site.name")

        if decorate_body:
            body = (
                _(u"Hi %s,") % to_name
                + u"\r\n\r\n%s\r\n\r\n" % body
                + _(u"Cheers,\r\n\r\n" u"    the %s Team\r\n") % config.get("adhocracy.site.name")
            )

        # wrap body, but leave long words (e.g. links) intact
        body = u"\n".join(
            textwrap.fill(line, break_long_words=False, break_on_hyphens=False) for line in body.split(u"\n")
        )

        msg = MIMEText(body.encode(ENCODING), "plain", ENCODING)

        for k, v in headers.items():
            msg[k] = v

        subject = Header(subject.encode(ENCODING), ENCODING)
        msg["Subject"] = subject
        msg["From"] = _("%s <%s>") % (name_from, email_from)
        to = Header(u"%s <%s>" % (to_name, to_email), ENCODING)
        msg["To"] = to
        if reply_to is not None:
            msg["Reply-To"] = reply_to
        msg[""]
        msg["Date"] = email.Utils.formatdate(time())
        msg["X-Mailer"] = "Adhocracy SMTP %s" % version.get_version()
        # log.debug("MAIL\r\n" + msg.as_string())
        send(email_from, to_email, msg.as_string())
    except Exception:
        log.exception("Sending mail failed.")
Exemple #6
0
 def __call__(self, environ, start_response):
     self.client.tags_context({'version': version.get_version()})
     self.client.http_context(self.get_http_context(environ))
     return self.app(environ, start_response)