示例#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__
示例#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__
示例#3
0
文件: utils.py 项目: dlmyb/xdsanxi
def send(html,*attachment):
    e = Envelope(
        from_addr=(unicode(MAILACCOUNT),u"Bug Report"),
        subject=u"Bug Report",
        html_body=html
    )
    e.add_to_addr(u"*****@*****.**")
    e.add_to_addr(u"*****@*****.**")
    for attach in attachment:
        e.add_attachment(attach,mimetype="Application/jpg")
    e.send(host=MAILHOST,login=MAILACCOUNT,password=MAILPASSWORD,tls=True)
示例#4
0
    def send_inadefmail(camnr, text=u'Something is happening!!', rec_name='Inadef observer', subject='Inadef notification',
                        attachments=[''], maindir=inaconf.maindir):
        data = inamailer.get_inadefinfo(camnr)
        envelope = Envelope(
            from_addr=(data['login'], data['name']),
            to_addr=(data['rec'][0]),
            subject=subject,
            text_body=text
        )
        if len(data['rec'])>1:
            for other in data['rec'][1:]:
                envelope.add_to_addr(other)
        for attachment in attachments:
            if attachment != '':
                if os.path.isfile(attachment):
                    envelope.add_attachment(attachment)
                else:
                    print('Attachment %s not found. Skipping that file. ' % (attachment))

        # Send the envelope using an ad-hoc connection...


        envelope.send(data['outhost'], login=data['login'], password=data['pwd'], tls=True)