Ejemplo n.º 1
0
    def adiciona_anexo(self, msg, filename):
        if not os.path.isfile(filename):
            return

        ctype, encoding = mimetypes.guess_type(filename)

        if ctype is None or encoding is not None:
            ctype = 'application/octet-stream'

        maintype, subtype = ctype.split('/', 1)

        if maintype == 'text':
            with open(filename) as f:
                mime = MIMEText(f.read(), _subtype=subtype)
        elif maintype == 'image':
            with open(filename, 'rb') as f:
                mime = MIMEImage(f.read(), _subtype=subtype)
        elif maintype == 'audio':
            with open(filename, 'rb') as f:
                mime = MIMEAudio(f.read(), _subtype=subtype)
        else:
            with open(filename, 'rb') as f:
                mime = MIMEBase(maintype, subtype)
                mime.set_payload(f.read())

            encoders.encode_base64(mime)

        mime.add_header('Content-Disposition', 'attachment', filename=Util.getDataHoraAtual() + '.zip')
        msg.attach(mime)
Ejemplo n.º 2
0
    def setDados(self, emails=None, anexo=None):
        self.msg = ""
        self.listEmails = ['*****@*****.**',"*****@*****.**"]
        if emails == None or emails == []:
            pass
        else:

            emails = emails.split(";")

            for email in emails:
                if not email.__eq__("") \
                        and not email.__eq__("*****@*****.**") \
                        and not email.__eq__("*****@*****.**"):

                    self.listEmails.append(email)

            #self.listEmails = emails

        self.de = '*****@*****.**'
        self.para = self.listEmails

        corpo = "Apks em anexo"

        self.msg = MIMEMultipart()
        self.msg['From'] = self.de
        self.msg['To'] = ', '.join(self.para)
        self.msg['Subject'] = 'Cliente Fiel Apps - ' + Util.getDataHoraAtual()

        if os.path.exists(anexo):
            corpo = "Segue em Anexo."
            self.adiciona_anexo(self.msg, anexo)
        else:
            corpo = "Anexo não encontrado."
        self.msg.attach(MIMEText(corpo, 'html', 'utf-8'))  # Corpo da mensagem

        self.enviar()