コード例 #1
0
    def test_seq_parts_in_a_multipart(self):
        outer = MIMEBase('multipart', 'mixed')
        outer['Subject'] = 'A subject'
        outer['To'] = '*****@*****.**'
        outer['From'] = '*****@*****.**'
        outer.preamble = ''
        outer.epilogue = ''
        msg = MIMEText('hello world')
        outer.attach([msg])
        outer.set_boundary('BOUNDARY')
        self.assertEqual(outer.as_string(), '''\
Content-Type: multipart/mixed; boundary="BOUNDARY"
MIME-Version: 1.0
Subject: A subject
To: [email protected]
From: [email protected]

--BOUNDARY
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit

hello world

--BOUNDARY--
''')        
コード例 #2
0
ファイル: mail.py プロジェクト: larsimmisch/aculab
    def run(self):
        try:
            subject = 'Answering machine message'
            txt = 'See audio attachment'
            
            if self.cli:
                subject = 'Answering machine message from %s' % self.cli
                subject, txt = self.name_lookup(subject, txt)

            msg = MIMEBase('multipart', 'mixed')
            msg['Subject'] = subject
            msg['Date'] = email.Utils.formatdate()
            msg['From'] = smtp_from
            msg['To'] = ', '.join(smtp_to)
            # this is not normally visible
            msg.preamble = 'This is a message in MIME format.\r\n'
            # Guarantees the message ends in a newline
            msg.epilogue = ''

            # attach text comment
            msg.attach(MIMEText(txt))

            if self.file:
                d = self.file.read()
                att = MIMEAudio(wav_header(d, WAVE_FORMAT_ALAW) + d, 'x-wav',
                                name=time.strftime('%Y-%m-%d-%H-%M-%S') + '.wav')
            
                msg.attach(att)

                # close the file opened in the recording
                self.file.close()
                self.file = None

            if self.call:
                # disconnect the call
                self.call.disconnect()
                self.call = None
        
            smtp = smtplib.SMTP(smtp_server)
            smtp.sendmail(smtp_from, smtp_to, msg.as_string(unixfrom=0))
            smtp.close()

        except:
            log.warn('answering machine email failed', exc_info=1)
            return

        log.info('answering machine mail sent from %s' % self.cli)
コード例 #3
0
    def test_no_parts_in_a_multipart(self):
        outer = MIMEBase('multipart', 'mixed')
        outer['Subject'] = 'A subject'
        outer['To'] = '*****@*****.**'
        outer['From'] = '*****@*****.**'
        outer.preamble = ''
        outer.epilogue = ''
        outer.set_boundary('BOUNDARY')
        msg = MIMEText('hello world')
        self.assertEqual(outer.as_string(), '''\
Content-Type: multipart/mixed; boundary="BOUNDARY"
MIME-Version: 1.0
Subject: A subject
To: [email protected]
From: [email protected]

--BOUNDARY


--BOUNDARY--
''')