Ejemplo n.º 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.")
Ejemplo n.º 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.")
Ejemplo n.º 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.")
Ejemplo n.º 4
0
Archivo: mail.py Proyecto: whausen/part
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.")
Ejemplo n.º 5
0
Archivo: mail.py Proyecto: alkadis/vcv
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.")
Ejemplo n.º 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)