I am getting "STARTTLS extension not supported by server" while attaching more than 1 MB file with the mail. While attaching less than 1 MB file the exception is not being generated in python.
if file_size <= ATTACHMENT_FILE_SIZE :
print('in if condition')
logger.info(f'{thread_name} : In If Condition')
mailDetails.attach(MIMEText(body_to_be_sent, "html"))
attachment = open(filepath, 'rb')
payload = MIMEBase('application', 'octet-stream')
payload.set_payload(attachment.read())
encoders.encode_base64(payload)
payload.add_header('Content-Disposition', "attachment; filename= %s" % f'''{file_name}.xlsx''')
mailDetails.attach(payload)
try:
connection = smtplib.SMTP(SMTPserver)
connection.ehlo()
connection.starttls()
connection.set_debuglevel(False)
connection.login(SMTPUSERNAME, SMTPPASSWORD)
text = mailDetails.as_string()
connection.sendmail(FROM_MAIL_ADDRESS,toAddress.split(",") + ccAddress.split(",")+bccAddress.split(","), text)
logger.info(f'{thread_name} : Mail Sent successfully')
# os.remove(filepath)
Aucun commentaire:
Enregistrer un commentaire