Search code examples
pythonemailflaskgmailbulk-mail

HTML wont work when I send a message with CKEditor


Right now I'm trying to send bulk messages in an app made with Python. Now, when I do it, the message that it's supposed to be formatted with HTML won't renderize.

emails = [c for c in view_contactos]
    if add.validate_on_submit(): #validamos datos
        subject = add.title.data
        body_message = add.body.data
        #conexion al server
        context = ssl.create_default_context()
        server = smtplib.SMTP_SSL('smtp.gmail.com', DevConfig.MAIL_PORT, context=context)
        server.login(DevConfig.MAIL_USERNAME, DevConfig.MAIL_PASSWORD)
        #envio del correo
        for row in emails:
            em = EmailMessage()
            em['From'] = DevConfig.MAIL_USERNAME
            em['To'] = row
            em['Subject'] = subject
            em.set_content(body_message)
            server.send_message(em)

        server.close()
        print('done')

This is the code Im using to send the messages

And this is an example of how you can see it in gmail

I am trying to send bulk html messages, I want the messages to be rendered when they are delivered to their recipients


Solution

  • In the line em.set_content(body_message) I had to write ", subtype="html" after the body_message

    em.set_content(body_message, subtype="html")