Email sending as HTML code

I would like to send an email that is to be sent as HTML.

Neither I nor the AI can find a solution.

configuration.yaml

default_config:

homeassistant:
  unit_system: metric
  currency: EUR
  time_zone: Europe/Berlin
  language: de
  packages:
    knx:                !include 1_KNX.yaml
    wettervorhersage:   !include 2_Wettervorhersage.yaml
    strom:              !include 3_Strom.yaml
    email:              !include 4_Email_versand.yaml
[..]

4_Email_versand.yaml

# Automation-Eintrag
automation:
  - alias: Email um 23:59 senden
    trigger:
      - platform: time
        at: "23:59:59"
    action:
      - service: script.sende_testmail

# Notify-Eintrag
notify:
  - platform: smtp
    name: email_test
    server: mail.*********.de
    port: 25
    sender: info@****.de
    recipient:
      - info@*****.de
    sender_name: "Home Assistant"

# Script-Eintrag
script:
  sende_testmail:
    sequence:
      - service: notify.email_test
        data_template:
          title: "Test-E-Mail mit HTML und CSS"
          message: >
            <!DOCTYPE html>
            <html>
            <head>
              <style>
                body {
                  font-family: Arial, sans-serif;
                  line-height: 1.6;
                  color: #333;
                }
                h1 {
                  color: #5e9ca0;
                }
                p {
                  font-size: 16px;
                }
              </style>
            </head>
            <body>
              <h1>Test der HTML-Formatierung</h1>
              <p>Dies ist ein einfacher Test, um die HTML- und CSS-Formatierung in einer E-Mail zu überprüfen.</p>
              <p style="color: #ff1f00;">Text in Rot</p>
              <p style="color: #4ab6ff;">Text in Blau</p>
              <p style="color: #00ff00;">Text in Grün</p>
            </body>
            </html>

The Mail goes out… is not displayed correctly in Outlook and on the android cell phone. I see the HTML code.

Do you have examples or can you correct my code?

THANKS

See the documentation:

Using up-to-date syntax (action:, data:, which the AIs don’t know):

script:
  sende_testmail:
    sequence:
      - action: notify.email_test
        data:
          title: "Test-E-Mail mit HTML und CSS"
          message: "Test message, plain text"
          data:
            html: >
              <!DOCTYPE html>
              <html>
              <head>
                <style>
                  body {
                    font-family: Arial, sans-serif;
                    line-height: 1.6;
                    color: #333;
                  }
                  h1 {
                    color: #5e9ca0;
                  }
                  p {
                    font-size: 16px;
                  }
                </style>
              </head>
              <body>
                <h1>Test der HTML-Formatierung</h1>
                <p>Dies ist ein einfacher Test, um die HTML- und CSS-Formatierung in   einer E-Mail zu überprüfen.</p>
                <p style="color: #ff1f00;">Text in Rot</p>
                <p style="color: #4ab6ff;">Text in Blau</p>
                <p style="color: #00ff00;">Text in Grün</p>
              </body>

Danke danke danke. Works

1 Like