예제 #1
0
파일: mail.py 프로젝트: goura/karesansui
    def create_multipart_message(self):
        self.msg = MIMEMultipart('mixed')
        self.create_base_header()
        text_msg = MIMEText(self.body, 'plain', self.encoding)
        self.msg.attach(text_msg)

        for _attach in self.attach:
            content_type = guess_type(_attach)[0]
            if content_type is None:
                content_type = "application/octet-stream"

            main_type, sub_type = content_type.split('/', 1)
            
            _part = MIMEBase(main_type, sub_type)
            _part['Content-ID'] = _attach
            _part.set_payload(open(_attach).read())
            Encoders.encode_base64(_part)
            _part.__delitem__('Content-Type')
            _part.add_header('Content-Type', content_type, name=os.path.basename(_attach))
            self.msg.attach(_part)
예제 #2
0
    def create_multipart_message(self):
        self.msg = MIMEMultipart('mixed')
        self.create_base_header()
        text_msg = MIMEText(self.body, 'plain', self.encoding)
        self.msg.attach(text_msg)

        for _attach in self.attach:
            content_type = guess_type(_attach)[0]
            if content_type is None:
                content_type = "application/octet-stream"

            main_type, sub_type = content_type.split('/', 1)

            _part = MIMEBase(main_type, sub_type)
            _part['Content-ID'] = _attach
            _part.set_payload(open(_attach).read())
            Encoders.encode_base64(_part)
            _part.__delitem__('Content-Type')
            _part.add_header('Content-Type',
                             content_type,
                             name=os.path.basename(_attach))
            self.msg.attach(_part)