Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mail] sendMail and sendHtmlFail errors for UI rules #11838

Closed
rkoshak opened this issue Dec 21, 2021 · 30 comments · Fixed by #12568
Closed

[Mail] sendMail and sendHtmlFail errors for UI rules #11838

rkoshak opened this issue Dec 21, 2021 · 30 comments · Fixed by #12568
Labels
bug An unexpected problem or unintended behavior of an add-on

Comments

@rkoshak
Copy link
Contributor

rkoshak commented Dec 21, 2021

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.

@rkoshak rkoshak added the bug An unexpected problem or unintended behavior of an add-on label Dec 21, 2021
@openhab-bot
Copy link
Collaborator

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/mail-binding-errors-sending-mail-unsupporteddatatypeexception-text-plaijn-charset-utf-8/130365/7

@openhab-bot
Copy link
Collaborator

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/openhab-3-2-release-discussion/130327/30

@openhab-bot
Copy link
Collaborator

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/mail-binding-unsupporteddatatypeexception-error/130530/3

@openhab-bot
Copy link
Collaborator

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/javascript-email-ioexemption/130910/2

@csowada
Copy link

csowada commented Jan 17, 2022

Hello @jpg0 and @digitaldan,

this issue is marked as mail binding issue. But I was able to fix the by just removing the line from the jsscripting binding. After that I was able to send mails again.

I think it hase something to do with the change for another class loading issues #11222

@openhab-bot
Copy link
Collaborator

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/mail-binding-errors-sending-mail-unsupporteddatatypeexception-text-plaijn-charset-utf-8/130365/15

@OlegAndreych
Copy link
Contributor

I'm having this issue with the Groovy scripting. So it seems like it's not specific for the JS scripting.

@edwolfe3
Copy link

OH3.2: I installed the Mail binding because i need to get a reliable way to be alerted to an issue. So I was going to send email-text to my phone. However, I get this problem. Two questions: 1) as this seems like the cleanest solution, is there an ETA on a fix? 2) If no fix coming soon, is there a work around, another option, etc. that can be utilized either permanently or temporarily?

@kstuken
Copy link

kstuken commented Jan 23, 2022

is there a work around, another option, etc. that can be utilized either permanently or temporarily?

I am sure there is better or more elegant solutions. But since I did not want to wait with migrating my rules to JS, I have just built myself a quick and dirty workaround by:

  • creating a string item
  • in the JS rule, not being able to send the email from there, sendCommand() a JSON containing the relevant email info (recipient, subject, message) to the string item
  • creating a DSL rule that is triggered by the command to string item, parses the JSON, and then send the email (and then clears the string item via postUpdate())

That way, I can send emails from any JS rule by using that string item.
Once this bug is fixed, I can then just quickly replace the sendCommand in the JS rule with the respective mailAction command

@martychristensen
Copy link

Hi Kstuken, can you post your creation?

is there a work around, another option, etc. that can be utilized either permanently or temporarily?

I am sure there is better or more elegant solutions. But since I did not want to wait with migrating my rules to JS, I have just built myself a quick and dirty workaround by:

  • creating a string item
  • in the JS rule, not being able to send the email from there, sendCommand() a JSON containing the relevant email info (recipient, subject, message) to the string item
  • creating a DSL rule that is triggered by the command to string item, parses the JSON, and then send the email (and then clears the string item via postUpdate())

That way, I can send emails from any JS rule by using that string item. Once this bug is fixed, I can then just quickly replace the sendCommand in the JS rule with the respective mailAction command

Hi Kstuken, can you post your creation?

@edwolfe3
Copy link

@kstuken I'll give it a try.

I agree with @martychristensen, it would be nice to see your "creation" for reference.

@edwolfe3
Copy link

edwolfe3 commented Jan 24, 2022

@kstuken did I do something wrong or stumble across another issue with javascript in 3.2? In my JS rule, I issue the following command (per documentation)

items.getItem("WolfeDen_Mail").sendCommand("redacted")

However, I get:

TypeError: items.getItem is not a function

??

@edwolfe3
Copy link

edwolfe3 commented Jan 24, 2022

It seems like javascript has to many issues. I created a dsl rule to replace my js rule and all is fine.

UPDATE: it worked ONCE and then stopped. Now I'm getting:

javax.activation.UnsupportedDataTypeException: text/plain; charset=UTF-8

so I'm back to square one with the Mail binding.

@kstaniek can you post how your DSL script is working as I can't get anything related to mail work.

@kstuken
Copy link

kstuken commented Jan 24, 2022

Sure, if that helps:

Here's the item:
String Mailtransporter "JSON String with values for mailer"

Here's the command sent in JS script

            const mailObject = {
                to: "some@email.com",
                subject: "subject line",
                message: "Message body goes here...",
            };
            items.getItem("Mailtransporter").postUpdate(JSON.stringify(mailObject));

And here's the DSL rule to pick it up and send the email:

rule "Mailer"
when
    Item Mailtransporter received command
then

    if (receivedCommand != NULL && receivedCommand != UNDEF && receivedCommand.toString != "") {
        val String json = receivedCommand.toString
        val String recipient  = transform("JSONPATH", "$.to", json)
        val String subject  = transform("JSONPATH", "$.subject", json)
        val String message  = transform("JSONPATH", "$.message", json)

        val mailActions = getActions("mail","mail:smtp:yourmail")
        mailActions.sendMail(recipient, subject, message)

        Mailtransporter.postUpdate("")
    }

end

@markormesher
Copy link

@kstuken What version are you running? I'm on openhab:3.2.0-debian and get the same error UnsupportedDataTypeException even via rules DSL, so it's interesting you're only having problems with JS rules. My rule for reference is:

rule "Debug: Send Email"
when
  // manual trigger only
  Item debug_neverChangingValue changed to "this-wont-happen"
then
  getActions("mail", "mail:smtp:migadu").sendMail("<email>", "OpenHAB Test Email", "Sent from OpenHAB")
end

@edwolfe3
Copy link

edwolfe3 commented Jan 24, 2022 via email

@kstuken
Copy link

kstuken commented Jan 24, 2022

I am on OH3.2 on openhabian, and using the JSScripting Add-on (ie ECMAScript 2021+ with the underlying openhab-js library). All my rules, as well as the mail thing definition are files based.
I have no idea where your case might be failing, but looking at the OH forum it appears others have run into that issue before.

@jpg0
Copy link
Contributor

jpg0 commented Jan 25, 2022

Notes regarding a quick investigation:

  • The failure is happening in javax.activation somewhere
  • It seems that openHAB is using servicemix as an implementation here (https://github.com/apache/servicemix-specs/)
  • The failure may be happening in the CommandMap class as there is some funny business going on there regarding classloaders. In the failure case, there is nothing there, hence the inability to locate a handler for text/plain
  • It's not yet clear to me where the success case should be getting something there instead (I have tried creating DSL script in the UI, but that also fails for me)

@edwolfe3
Copy link

edwolfe3 commented Jan 25, 2022

@kstuken I'm UI based.

Is there some workaround (that doesn't require rewriting the world) to get mail working until a fix can be made?

@AndReinhar
Copy link

Just FYI - the command seems to work fine when running it at startup - I have a rule to send me an email every startup (level 100) and this works. However running the rule manually does not work.

@edwolfe3
Copy link

edwolfe3 commented Jan 26, 2022

FYI: My rule is set to run everyday at 5;30. Today it ran and the email was sent. Just when I click "run now" it gets the error.

UPDATE: I have the DSL rule triggered by the update of a string item. Every time the item is updated the rule fires and sends the email. However, it is only if I click on "run now" in the UI script editor that it returns:

javax.activation.UnsupportedDataTypeException: text/plain; charset=UTF-8

@opape
Copy link

opape commented Jan 26, 2022

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..

@J-N-K
Copy link
Member

J-N-K commented Jan 26, 2022

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

@fullmoonguru
Copy link

fullmoonguru commented Jan 28, 2022

I was hoping that triggering a rule with time would be a good work-around but that's not the case for me.

I THOUGHT this had been an intermittent issue for me before and I have just verified that. I set up a test rule to send an email every 5 minutes and I got 5 in a row.

So then I tried modifying a temp alert rule to trigger every 5 minutes and it did not work.

Then I un-paused the email test rule and it no longer worked.

I created a new email test rule and it did not work.

This is javascript.

@openhab-bot
Copy link
Collaborator

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/mail-binding-errors-sending-mail-unsupporteddatatypeexception-text-plaijn-charset-utf-8/130365/21

@fullmoonguru
Copy link

Emails started working last night. I have 3 systems running openHABian OH3. I had a test email rule set to send an email on a time trigger (which wasn’t sending any) on one of these systems. I rebooted that system last night and woke up to a bunch of emails. I paused & unpaused the rule & it continues working. So I copied the rule to the other two systems. One started working, the other did not. I rebooted the one that wasn’t sending emails & it’s now working.

@openhab-bot
Copy link
Collaborator

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/openhab-3-3-milestone-discussion/132715/37

@openhab-bot
Copy link
Collaborator

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/mail-will-not-more-be-send/134230/5

@openhab-bot
Copy link
Collaborator

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/mail-binding-errors-sending-mail-unsupporteddatatypeexception-text-plaijn-charset-utf-8/130365/25

@openhab-bot
Copy link
Collaborator

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/cannot-send-mail-no-protocol/135334/10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of an add-on
Projects
None yet
Development

Successfully merging a pull request may close this issue.