티스토리 뷰

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
반응형
250x250
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함