티스토리 뷰

SWDesk

[Python] SendMail

inhae 2022. 7. 14. 22:20

SendMail()

    def SendMail(self, messageInfos, toAddress):
        smtp = self.GetSMTP()
        fromAddress = cConstants.thisEmailAddress

        subjectString = messageInfos['Subject']
        bodyMessage = messageInfos['BodyMessage']

        attachedFile = messageInfos.get('File')
        if attachedFile:
            msg = MIMEMultipart()
            aFile = open(attachedFile, 'rb')
            part1 = MIMEBase('application', 'octet_stream')
            part1.set_payload((aFile).read())
            encoders.encode_base64(part)
            part1.add_header('Content_Disposition', "attachment; filename= "+attachedFile)
            msg.attach(part1)
            msg.attach(MIMEText(bodyMessage, 'plain'))
        else:
            msg = MIMEText(bodyMessage)

        msg['Subject'] = subjectString
        msg['To'] = toAddress

        smtp.sendmail(fromAddress, toAddress, msg.as_string())
        smtp.quit()

 

반응형

'SWDesk' 카테고리의 다른 글

[Python] DataFrame 날짜순으로 정렬  (0) 2022.07.19
[Python] 문자열에 한글이 있는지 여부 확인  (0) 2022.07.17
JSON in the JSON Test  (0) 2022.07.13
[Python + PHP] Insert Datas  (0) 2022.07.12
[Python] Backup Files  (0) 2022.07.10