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()
반응형