Отправка электронной почты с вложением в python с ошибкой под https

У меня ошибка при попытке отправить письмо с вложенным pdf в python (Django) под https активным, но не получается под http, вот мой код:

from django.conf import settings
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders

sender_email_address =  sender@mail.com
email_password = myPass
email_smtp = smtp.gmail.com
email_subject = self.titulo 
receiver_email_address = receiver@gmail.com

remitente = sender_email_address
destinatarios = [receiver_email_address]
asunto = email_subject
cuerpo = self.cuerpo
ruta_adjunto = 'file.pdf'
nombre_adjunto = 'file.pdf'

mensaje = MIMEMultipart()
mensaje['From'] = remitente
mensaje['To'] = ", ".join(destinatarios)
mensaje['Subject'] = asunto
mensaje.attach(MIMEText(cuerpo, 'plain'))
archivo_adjunto = open(ruta_adjunto, 'rb')
adjunto_MIME = MIMEBase('application', 'octet-stream')
adjunto_MIME.set_payload((archivo_adjunto).read())
encoders.encode_base64(adjunto_MIME)
adjunto_MIME.add_header('Content-Disposition', "attachment; filename= %s" % nombre_adjunto)
mensaje.attach(adjunto_MIME)
sesion_smtp = smtplib.SMTP(email_smtp, '587') 
sesion_smtp.set_debuglevel(1)
sesion_smtp.ehlo()
sesion_smtp.starttls()
sesion_smtp.login(sender_email_address, email_password)
texto = mensaje.as_string()
sesion_smtp.sendmail(remitente, destinatarios, texto)
sesion_smtp.quit()

Этот код работает под http python manage.py runserver 0.0.0.0:9090

Вернуться на верх