Cannot send mail : no protocol

I am unable to send e-mails. I always get the same error
WARN Could not send mail : no protocol : e-mail message

I have setup two smtp servers, google and comcast and tried many different variations of port and security options.

I have setup a very simple script as follows

val mailActions = getActions(“mail”,“mail:smtp:12ca7ed032”)
mailActions.sendMail(“XXX@comcast.net,"xxx@yahoo.com",“subject”,“message”)

The mail thing code is

UID: mail:smtp:12ca7ed032
label: SMTP Comcast
thingTypeUID: mail:smtp
configuration:
hostname: smtp.comcast.net
password: user password
security: SSL
port: “25”
sender: xxx@comcast.net
username: xxx@comcast.net

This is the last configuration but I have also tested ports 465 and 587 and SSL/TLS security

If I run bundles:list I see the mail binding, so it seems to be active

I have read many threads with mail issues but they all seem to be related to either the smtp configuration or the syntax in the script which seem to be correct in my case

Can anyone guide me as to how to troubleshoot this issue?

Thank you

Carlos

  • Platform information:

    • Hardware: Windows 11
    • openHAB version: 3.2
  • Please post configurations (if applicable):

    • Items configuration related to the issue
    • Sitemap configuration related to the issue
    • Rules code related to the issue
    • Services configuration related to the issue
  • If logs where generated please post these here using code fences:

AFAIK, sendMail 's arguments are:

  • recipient
  • Subject
  • Body text

You’re calling it with 4 arguments. When I called it with 4 arguments, I got:

(ArgumentError) wrong number of arguments (given 4, expected 3)

Thank you, now I get a different error

with port 587
20:35:30.455 [WARN ] [hab.binding.mail.internal.SMTPHandler] - javax.mail.MessagingException: Could not connect to SMTP host: smtp.comcast.net, port: 587;
nested exception is:
javax.net.ssl.SSLException: Unsupported or unrecognized SSL message

or

with port 465

20:36:59.961 [WARN ] [hab.binding.mail.internal.SMTPHandler] - Sending the email to the following server failed : smtp.comcast.net:465
20:36:59.962 [WARN ] [hab.binding.mail.internal.SMTPHandler] - javax.mail.MessagingException: IOException while sending message;
  nested exception is:
        javax.activation.UnsupportedDataTypeException: text/plain; charset=UTF-8

with port 465 and STARTTLS

20:40:00.142 [WARN ] [hab.binding.mail.internal.SMTPHandler] - Sending the email to the following server failed : smtp.comcast.net:465
20:40:00.144 [WARN ] [hab.binding.mail.internal.SMTPHandler] - javax.mail.MessagingException: Exception reading response;
  nested exception is:
        java.net.SocketTimeoutException: Read timed out

This is what xfinity says are the smtp settings

Outgoing Mail Server Name: smtp.comcast.net
Outgoing Mail Server Port Number: 587 (SMTP)

    If Needed: 465 (SMTPS)

Encryption: TLS (use SSL if TLS isn't shown.)
Authentication: Type in your Comcast.net email address

Not sure what else to try

This isn’t a problem with the binding.

Use either:

  • Port 587 + STARTTLS, or
  • Port 465 + SSL/TLS

465 + STARTTLS is the wrong combination.
587 + SSL/TLS is the wrong combination

2 Likes

Thanks again but I just cannot get this to work. Either with Comcast or Google

I simplified the script

val mailActions = getActions(“mail”,“mail:smtp:dd7055cab0”)
mailActions.sendMail(“xxx@yahoo.com”,“openhab”,“Test”)

With port 587 and STARTTLS I get

17:30:03.782 [WARN ] [hab.binding.mail.internal.SMTPHandler] - Sending the email to the following server failed : smtp.gmail.com:587
17:30:03.783 [WARN ] [hab.binding.mail.internal.SMTPHandler] - javax.mail.MessagingException: IOException while sending message;
  nested exception is:
        javax.activation.UnsupportedDataTypeException: text/plain; charset=UTF-8

Same thing with port 465 and SSL/TSL

17:33:26.085 [WARN ] [hab.binding.mail.internal.SMTPHandler] - Sending the email to the following server failed : smtp.gmail.com:465
17:33:26.086 [WARN ] [hab.binding.mail.internal.SMTPHandler] - javax.mail.MessagingException: IOException while sending message;
  nested exception is:
        javax.activation.UnsupportedDataTypeException: text/plain; charset=UTF-8

Any idea what this means?
Thank you

I’ve just tested it using gmail. At first I got an NPE because in my text configuration for the things, I had port=587 (presumed that it was an integer).

When I changed the port to string i.e. port="587" it worked.

Here’s my things file:

Thing mail:smtp:gmail [ hostname="smtp.gmail.com", sender="myemail@addr", port="587", security="STARTTLS", username="xxxxxxxxxx@gmail.com", password="mypassword" ]

And my code (in jruby - but that should be irrelevant here)

things['mail:smtp:gmail'].sendMail('xxxxx@xxxx.com', 'test2', 'blahblah')

I received the test email in the recipient’s inbox. In this test, I used the same sender, username, and recipient

Could you show us your .things configuration? Perhaps the config validation could be improved so as not to generate this perplexing error.

Thank you for doing all these trials but it did not work for me
If I use the “587” as the port in the UI, the code shows port: ’ “587” ’ but the binding ignores it and send the default port (25) which times out.

Here is my thing code entering 587 (no quotes) in the UI

UID: mail:smtp:dd7055cab0
label: SMTP Google
thingTypeUID: mail:smtp
configuration:
  hostname: smtp.gmail.com
  password: my app password
  security: STARTTLS
  port: "587"
  sender: xxxx@gmail.com
  username: xxx@gmail.com

here is the script

val mailActions = getActions("mail","mail:smtp:dd7055cab0")
mailActions.sendMail("xxx@yahoo.com","openhab","Test")

and the error

21:53:52.287 [WARN ] [hab.binding.mail.internal.SMTPHandler] - Sending the email to the following server failed : smtp.gmail.com:587
21:53:52.289 [WARN ] [hab.binding.mail.internal.SMTPHandler] - javax.mail.MessagingException: IOException while sending message;
  nested exception is:
        javax.activation.UnsupportedDataTypeException: text/plain; charset=UTF-8

If I remove the quotes in the code (port: 587), then the binding thinks it is a real number and sends 587.0 as the port which gives many errors

The quotes are only applicable for file based configuration. For UI based, enter it in the UI without quotes, and in the “Code” tab you’ll see it with quotes.

I couldn’t recreate the same errors that you had with jruby, but when I tried creating a GUI script using RulesDSL, I can see the exact same error!

Maybe related?

A fix for this is waiting for review.

I see the same behavior described in that discussion. The mail is sent if the script is triggered by the rule. If I click on run on the script itself then I get the error. At least now it works, it is just difficult to test new scripts.