Mail Binding errors, but it used to work

I’m not exactly sure when this stopped working, but I’ve been updating OH every now & then and I’m on 2.5.8 currently. When I try to fire off an email through a rule, I see the following error in my openhab log

2020-09-01 15:50:46.600 [INFO ] [pse.smarthome.model.script.EmailTest] - Email test has been triggered ON
2020-09-01 15:50:46.699 [WARN ] [javax.mail                          ] - expected resource not found: /META-INF/javamail.default.address.map
2020-09-01 15:50:48.093 [WARN ] [ab.binding.mail.internal.SMTPHandler] - Sending the email to the following server failed : <snipped.mailserver.name>:465
2020-09-01 15:50:48.096 [WARN ] [ab.binding.mail.internal.SMTPHandler] - javax.mail.MessagingException: IOException while sending message;
  nested exception is:
	javax.activation.UnsupportedDataTypeException: text/plain; charset=UTF-8

But yet if I do a tcpdump, I see a full TCP conversation on port 465 with my email server (about 35 packets).

One of the recent openhabian updates I did upgraded my Java (to /opt/jdk/zulu8.48.3.246-ca-jdk8.0.265-linux_aarch32hf/bin/java), which I have backed down to my original version:

java -version

openjdk version "1.8.0_222"
OpenJDK Runtime Environment (Zulu8.40.0.178-CA-linux_aarch32hf) (build 1.8.0_222-b178)
OpenJDK Client VM (Zulu8.40.0.178-CA-linux_aarch32hf) (build 25.222-b178, mixed mode, Evaluation)

Any ideas? I’m using SSL and my username and password for the server have not changed. I tried removing the binding, readding it and recreating my mail server thing. Also manually creating the thing in a .things file vs in paperui too. Multiple reboots, no changes.

I’m used to that javamail.default.address.map error, and it has never caused any issues.

here’s my rule

val mailActions = getActions("mail","mail:smtp:pairsmtp3")

rule "email rule test"
when 
Item Neo1Switch changed to ON
then
  {
    logInfo("EmailTest","Email test has been triggered ON")
	mailActions.sendMail("myemailaddress@here.com", "Just a test email to me", "Email test ON")
  }
end

Thanks!

Does sending the mail with the sendHtmlMail action result in the same error ?

I updated the rule, but receive a different error and no email delivered (Still see full tcpdump conversation)

2020-09-02 08:33:35.642 [INFO ] [pse.smarthome.model.script.EmailTest] - Email test has been triggered ON
2020-09-02 08:33:35.660 [WARN ] [javax.mail                          ] - expected resource not found: /META-INF/javamail.default.address.map
2020-09-02 08:33:36.703 [WARN ] [ab.binding.mail.internal.SMTPHandler] - Sending the email to the following server failed : <mailserver.name.here>:465
2020-09-02 08:33:36.704 [WARN ] [ab.binding.mail.internal.SMTPHandler] - javax.mail.MessagingException: IOException while sending message;
  nested exception is:
	javax.activation.UnsupportedDataTypeException: multipart/alternative; 
	boundary="----=_Part_46_5296120.1599060815652"

I’ll poke around a bit more today too. My last automated emails were on 8/24 and I believe I was on 2.5.7 then fwiw

but you can’t see the content of the packages as the communication is encrypted, right ?

I added a local email relay using port 25, so I can see further into this.

220 jptubuntu.local.com ESMTP Sendmail 8.15.2/8.15.2/Debian-18; Thu, 3 Sep 2020 13:31:45 -0700; (No UCE/UBE) logging access from: 10.5.5.242-[10.5.5.242]
EHLO openHABianPi
250-jptubuntu.local.com Hello [10.5.5.242], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-EXPN
250-VERB
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-DELIVERBY
250 HELP
MAIL FROM:openhabsender@local.com
250 2.1.0 openhabsender@local.com… Sender ok
RCPT TO:openhabsending@local.com
250 2.1.5 openhabsending@local.com… Recipient ok
DATA
354 Enter mail, end with “.” on a line by itself
421 4.4.1 collect: unexpected close on connection from [10.5.5.242], from=openhabsender@local.com

I can share more info on this too, but I see the openhab server send a FIN ACK abruptly after that packet for code 354. The email server sends that 421 and then the OH server sends a Reset packet.

I’ll try reinstalling the Mail binding again and clearing the cache etc too, and of course some reboots.

here’s my temp things file:

 Thing mail:smtp:pairsmtp3 [ hostname="10.5.5.18" ]

Do you still get the same INFO/WARNING messages in the logfile ?

Well, I have no idea what happened on this. I ended up trying to downgrade OH to 2.5.7-1 and that went horribly (the docs do say this is a bad idea, it basically did a full stop and was not recoverable). I tried going back to 2.5.8, reinstalled packages etc, and it wasn’t working - Karaf wasn’t starting at all, I was wasting too much time.

Anyway, I have been meaning to move from my Pi 3b+ to an old Intel Nuc, which I did. I did a clean ubuntu 20.04 install, OH install, and then a restore from a backup I had on Sept 1st. Everything is working fine, emails are working w/ the original config I had, zwave came right up, life is good.

I guess it was specific to me here, strange behavior for sure though.

As a note to everyone, make sure you take regular backups! I also have a cron job that SCP’s them to another server as a backup too. The backup / restore process is amazing and works great!

Thanks for all the time and thoughts on this.

I’ve just upgraded to 3.0.2 and Java 11 as is now apperently required.

java -fullversion
openjdk full version "11.0.11+9-post-Raspbian-1deb10u1"

Now when I try to send an email I’m getting the same error as you did:

2021-06-09 21:02:56.356 [WARN ] [ab.binding.mail.internal.SMTPHandler] - Sending the email to the following server failed : smtpserver:465
2021-06-09 21:02:56.362 [WARN ] [ab.binding.mail.internal.SMTPHandler] - javax.mail.MessagingException: IOException while sending message;
  nested exception is:
	javax.activation.UnsupportedDataTypeException: text/plain; charset=UTF-8

I don’t fancy going back to Java 8 and OH2.x, so did you find a solution for this?

I also just something that might be related (but for karaf):
Error while sending email because of javax.activation

But you did not follow the prerequisits. openJDK is not recommended for known issues. Please change to Zulu 11.
This might not be related to your issue, but might prevent further ones.

Hi Hans-Jörg,
I followed this page: Migrating from openHAB 2 to openHAB 3
and it says:

openHAB 3 requires Java 11. Most modern Linux OS have an openjdk-11-jdk package available for you to install but alternative solutions such as Zulu’s OpenJDK (which openHABian can install for you) are available and these may run faster on 32-bit armhf platforms such as the Raspberry Pi.

On the migration page there is no mention that only zulu should be used or that there are problems with openjdk-11-jdk.

What are the problems with openjdk? Maybe the migration page needs to be updated if that is indeed the case.

Obviously I’ll try installing zulu and see if it resolves the problem but I don’t think that it will.

See the installation prerequisits for openHAB 3, there is also a link to the known issues.
Same recommendation existed for openHAB 2.

Am I looking in the wrong place?
openHABian - Hassle-free openHAB Setup and Zulu is mentioned in the section titled “Interactive install on generic x86 Linux”.

I’m upgrading an “openHABian” Raspberry Pi installation (not that it should matter).

The migration page says “openjdk-11-jdk”, the openHABian installation page says “Out of the box, the openHABian image provides; * Zulu Embedded OpenJDK Java 11 or AdoptOpenJDK”.

They should both, IMHO link to the “main” installation page, where openjdk is “not recommended” (Installation Overview | openHAB)

I followed the instructions on the migration page, if they differ from the recommended requirements then the pages need to be amended.

OK switched to Zulu:

java -version
openjdk version "11.0.11" 2021-04-20 LTS
OpenJDK Runtime Environment Zulu11.48+21-CA (build 11.0.11+9-LTS)
OpenJDK Client VM Zulu11.48+21-CA (build 11.0.11+9-LTS, mixed mode)

and the issue is still there:

2021-06-10 12:29:09.533 [WARN ] [ab.binding.mail.internal.SMTPHandler] - Sending the email to the following server failed : smtpserver:465
2021-06-10 12:29:09.611 [WARN ] [ab.binding.mail.internal.SMTPHandler] - javax.mail.MessagingException: IOException while sending message;
  nested exception is:
	javax.activation.UnsupportedDataTypeException: text/plain; charset=UTF-8

Looks to me that the smtp server name is wrong and you have the port number there instead.

I only changed the name of the server and the port was added automatically.

It worked fine in OH2+Java8 before updating to OH3+Java11, so I know that the server settings (hostname, port, user+password, etc.) are fine.

It is mail extension saying that the header setting the content type is incorrect. I also tried sendHtmlMail and that fails with a similar error message.

would you mind to share your thing and rule definition ?

I hope this is what you want (contents changed)
SMTP Thing:

UID: mail:smtp:d7887864
label: SMTP
thingTypeUID: mail:smtp
configuration:
  hostname: smtp.provider.com
  security: SSL
  password: myPassword
  sender: openhab@mynetwork.com
  username: openhab@mynetwork.com
location: WWW

Rule: Triggered when door is opened, I want to add an “out of the house” state so I’ll get an Email if the door is opened when I’m not at home:

triggers:
  - id: "4"
    label: an item state is updated
    description: This triggers the rule if an item state is updated (even if it does
      not change).
    configuration:
      itemName: FrontDoor
      state: OPEN
    type: core.ItemStateUpdateTrigger
conditions: []
actions:
  - inputs: {}
    id: "3"
    label: execute sendMail
    description: Use script to send mail
    configuration:
      type: application/javascript
      script: >-
        mailActions = actions.get("mail","mail:smtp:d7887864")

        mailActions.sendMail("me@mynetwork.com", "Front door opened", "Front door was opened"!")
    type: script.ScriptAction

I tested the binding with a DSL rule’s file and I am not used to rules from the UI yet so my concern might be not relevant …

Is this correct ( pay attention the end of the line ). There is a !" after the closing ".

I would suggest to remove !" at least for a test.

I must have copied something incorrectly, sorry.

… , “Front door opened”, “Front door was opened”)

Even without the exclamation marks I’m still getting same Java error