Mail binding error handling

Hi all,
I have searched in the documentation but could not find the answer.
The question is: can someone explain to me how to catch and handle the error messages generated by the new Mail Binding on “SendMail” command.
In particular, I would like to know which error messages are thrown by this binding and what are their meaning.

thanks

As far as I understand the java code the binding uses other java modules/classes

import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailException;

exception handling is done based on these modules. Means error messages are from that modules.

find . -type f -exec grep  -i logger {} \;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
    private final Logger logger = LoggerFactory.getLogger(POP3IMAPHandler.class);
                        logger.info("missing or empty folder name in channel {}", channel.getUID());
            logger.info("error when trying to refresh IMAP: {}", e.getMessage());
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
    private final Logger logger = LoggerFactory.getLogger(SMTPHandler.class);
            logger.warn("{}", e.getMessage());
                logger.warn("{}", e.getCause().toString());
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
    private final Logger logger = LoggerFactory.getLogger(SendMailActions.class);
            logger.warn("Cannot send mail as recipient is missing.");
                logger.info("Handler is null, cannot send mail.");
            logger.warn("Could not send mail: {}", e.getMessage());
            logger.warn("Could not send mail: {}", e.getMessage());
            logger.warn("Could not send mail: {}", e.getMessage());
            logger.warn("Cannot send mail as recipient is missing.");
                logger.warn("Handler is null, cannot send mail.");
            logger.warn("Could not send mail: {}", e.getMessage());
            logger.warn("Could not send mail: {}", e.getMessage());
            logger.warn("Could not send mail: {}", e.getMessage());

This again means that they should be error messages according to RFC documents.
So you should be able to take the warnings or error messages and google for them.

Do you have an example on hand that you need more information for ?

Does the Action not return a result string?

val mailResult = myMailActions.sendMail("blah" ...

It may not if it is asynchronous.

The docs do not mention a return value and none of the examples indicate that there is one.

Hi,
I have modified my rule as follows

val returnString = mailActions.sendMail("xx.xx@gmail.com", msg.toString, msg.toString)
logInfo("sendMail",returnString)

but I got the following error:

2020-06-18 12:21:03.128 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'gSendEmailOnChange trigger': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.LogAction.logInfo(java.lang.String,java.lang.String,java.lang.Object[]) on instance: null

So, how can I be sure that the email has been sent or how can I catch an error to resend it in case of internet absence?

Yes, my suggestion was rubbish I’m afraid. Even if it worked, the mail Action could only return a basic message e.g. about parameter errors.
The actual time consuming work of sending the mail will be done by the binding asynchronously, the Action does not stop and wait for it to happen, and there is no way to return a success/fail message to the rule.

The binding should be logging error messages, so you could use Log Reader binding to look out for those.

I think it would be a useful enhancement to the mail binding to provide some feedback, though.
One way might be to add a “Last sendmail results” string channel, that the binding could update with “OK” or “the error message” once a mail send was attempted/completed.
A companion dateTime channel could simply be updated with last success timestamp.
Worth opening a github enhancement request for the future, I’d say.

Or just blocking for up to the passed in amount of time like executeCommandLine and the sendHttp*Request actions.

I agree, having some way to learn whether the message was successfully sent or not would be handy.