Exemplo n.º 1
0
class ReplyMail(object):
    """An Envelope Object wrapper used to reply a mail easily. 
    """
    def __init__(self, orimail, from_name=None, charset='utf-8'):
        self.charset = charset

        from_addr = orimail.get_addr('to')[0]
        to_addr = orimail.get_addr('from')
        cc_addr = orimail.get_addr('cc')

        if not from_name:
            from_name = from_addr

        self.envelope = Envelope(
            from_addr=(from_addr, from_name),
            to_addr=to_addr,
            subject="RE:" + orimail.subject,
        )

        self.add_addr(cc_addr=cc_addr)

    def add_attachment(self, attfile):
        self.envelope.add_attachment(attfile)

    def set_subject(self, subject):
        self.envelope._subject = subject

    def set_body(self, text_body=None, html_body=None, charset='utf-8'):
        if text_body:
            self.envelope._parts.append(('text/plain', text_body, charset))

        if html_body:
            self.envelope._parts.append(('text/html', html_body, charset))

    def add_addr(self, to_addr=None, cc_addr=None, bcc_addr=None):
        if to_addr:
            for addr in to_addr:
                self.envelope.add_to_addr(addr)
        if cc_addr:
            for addr in cc_addr:
                self.envelope.add_cc_addr(addr)
        if bcc_addr:
            for addr in bcc_addr:
                self.envelope.add_bcc_addr(addr)

    def send(self, smtpserver=None, account=None):
        if smtpserver:
            smtpserver.send(self.msg)
        elif account:
            self.envelope.send(account.smtp,
                               login=account.username,
                               password=account.decrypt_password())
        else:
            logger.error("A SMTP server or mail account must be provided!.")
            return False

        return True

    def __repr__(self):
        return self.envelope.__repr__
Exemplo n.º 2
0
class ReplyMail(object):
    """An Envelope Object wrapper used to reply a mail easily. 
    """
    def __init__(self,orimail,from_name=None,charset='utf-8'):
        self.charset=charset

        from_addr = orimail.get_addr('to')[0]
        to_addr = orimail.get_addr('from')
        cc_addr = orimail.get_addr('cc')

        if not from_name:
            from_name = from_addr

        self.envelope = Envelope(
            from_addr = (from_addr,from_name),
            to_addr  = to_addr,
            subject = "RE:" + orimail.subject,
            )

        self.add_addr(cc_addr=cc_addr)

    def add_attachment(self,attfile):
        self.envelope.add_attachment(attfile)

    def set_subject(self,subject):
        self.envelope._subject = subject

    def set_body(self, text_body=None, html_body=None,charset='utf-8'):
        if text_body:
            self.envelope._parts.append(('text/plain', text_body, charset))

        if html_body:
            self.envelope._parts.append(('text/html', html_body, charset))

    def add_addr(self,to_addr=None,cc_addr=None,bcc_addr=None):
        if to_addr:
            for addr in to_addr:
                self.envelope.add_to_addr(addr)
        if cc_addr:
            for addr in cc_addr:
                self.envelope.add_cc_addr(addr)
        if bcc_addr:
            for addr in bcc_addr:
                self.envelope.add_bcc_addr(addr)

    def send(self,smtpserver=None,account=None):
        if smtpserver:
            smtpserver.send(self.msg)
        elif account:
            self.envelope.send(account.smtp,login=account.username,password=account.decrypt_password())
        else:
            logger.error("A SMTP server or mail account must be provided!.")
            return False

        return True

    def __repr__(self):
        return self.envelope.__repr__
Exemplo n.º 3
0
 def send_mail(self, message, subject):
     mail = Envelope(from_addr=self.mail_load.get('author',
                                                  self.email_author),
                     to_addr=self.mail_load['to'].split(';'),
                     subject=subject.format(version=self.candidate,
                                            target=env.name.upper()),
                     text_body=message % env.name.upper())
     if self.mail_load.get('cc'):
         for cc in self.mail_load['cc'].split(';'):
             mail.add_cc_addr(cc)
     mail.send(self.mail_load['server'])
Exemplo n.º 4
0
 def send_mail(self, message, subject):
     mail = Envelope(
         from_addr=self.mail_load.get('author', self.email_author),
         to_addr=self.mail_load['to'].split(';'),
         subject=subject.format(version=self.candidate, target=env.name.upper()),
         text_body=message % env.name.upper()
     )
     if self.mail_load.get('cc'):
         for cc in self.mail_load['cc'].split(';'):
             mail.add_cc_addr(cc)
     mail.send(self.mail_load['server'])
Exemplo n.º 5
0
 def send_mail(self, message, subject):
     mail = Envelope(
         from_addr=self.mail_class.get("author", self.email_author),
         to_addr=self.mail_class["to"].split(";"),
         subject=subject.format(version=self.candidate, target=env.name.upper()),
         text_body=message % env.name.upper(),
     )
     if self.mail_class.get("cc"):
         for cc in self.mail_class["cc"].split(";"):
             mail.add_cc_addr(cc)
     mail.send(self.mail_class["server"])