openhab-addons: [Mail] sendMail and sendHtmlFail errors for UI rules

Expected Behavior

When calling sendMail or sendHtmlMail the email is delivered.

Current Behavior

When calling sendMail the following error occurs:

2021-12-20 14:42:15.581 [WARN ] [ab.binding.mail.internal.SMTPHandler] - Sending the email to the following server failed : smtp.gmail.com:587
2021-12-20 14:42:15.581 [WARN ] [ab.binding.mail.internal.SMTPHandler] - javax.mail.MessagingException: IOException while sending message;
  nested exception is:
        javax.activation.UnsupportedDataTypeException: text/plain; charset=UTF-8

When calling sendHtmlMail the following error occurs:

2021-12-20 14:40:32.423 [WARN ] [ab.binding.mail.internal.SMTPHandler] - Sending the email to the following server failed : smtp.gmail.com:587
2021-12-20 14:40:32.424 [WARN ] [ab.binding.mail.internal.SMTPHandler] - javax.mail.MessagingException: IOException while sending message;
  nested exception is:
        javax.activation.UnsupportedDataTypeException: multipart/alternative; 
        boundary="----=_Part_21_1035614427.1640036431905"

In both cases the code is written in JSScripting through the UI. Based on reports (see https://community.openhab.org/t/mail-binding-errors-sending-mail-unsupporteddatatypeexception-text-plaijn-charset-utf-8/130365) the same error occurs in Nashorn and Rules DSL. But there is one report of it working in a .rules file so perhaps the difference is UI verses text file.

Possible Solution

Steps to Reproduce (for Bugs)

  1. Create a Mail thing

  2. Create a UI rule with a script action. Use JavaScript or Rules DSL as the action language and the following line (obviously change the email as appropriate):

    actions.get(“mail”, “mail:smtp:redacted”).sendMail(“redacted@redacted.com”, “Test”, “Test”)

  3. Watch the logs.

Context

I can no longer get alerts from openHAB via email.

Your Environment

runtimeInfo: version: 3.3.0 buildString: “Build #2651” locale: en-US systemInfo: configFolder: /openhab/conf userdataFolder: /openhab/userdata logFolder: /openhab/userdata/logs javaVersion: 11.0.13 javaVendor: Azul Systems, Inc. javaVendorVersion: Zulu11.52+13-CA osName: Linux osVersion: 5.4.0-91-generic osArchitecture: amd64 availableProcessors: 4 freeMemory: 47455416 totalMemory: 855638016 bindings:

  • astro
  • bluetooth
  • chromecast
  • ipcamera
  • mail
  • mqtt
  • network
  • networkupstools
  • openweathermap
  • roku
  • shelly
  • zigbee
  • zwave clientInfo: device: ios: false android: false androidChrome: false desktop: true iphone: false ipod: false ipad: false edge: false ie: false firefox: false macos: true windows: false cordova: false phonegap: false electron: false nwjs: false webView: false webview: false standalone: false os: macos pixelRatio: 2 prefersColorScheme: light isSecureContext: false locationbarVisible: true menubarVisible: true navigator: cookieEnabled: true deviceMemory: N/A hardwareConcurrency: 4 language: en-US languages:
    • en-US
    • en onLine: true platform: MacIntel screen: width: 1920 height: 1080 colorDepth: 24 support: touch: false pointerEvents: true observer: true passiveListener: true gestures: false intersectionObserver: true themeOptions: dark: light filled: true pageTransitionAnimation: default bars: filled homeNavbar: default homeBackground: default expandableCardAnimation: default userAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36 timestamp: 2021-12-21T17:54:28.243Z

Running in Docker.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 30 (2 by maintainers)

Most upvoted comments

That’s because of a different ClassLoader being used in both cases.

I can confirm this behavior. If the rule is triggered by the trigger (for me it is at a fixed time) the email is sent. If you click on “run now” in the UI you get the error message:

javax.mail.MessagingException: IOException while sending message;
  nested exception is:
	javax.activation.UnsupportedDataTypeException: text/plain; charset=UTF-8

I use a Jython script within the rule…