How to catch errors that occurred while sending an email?

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
maxlich
Active Member

How to catch errors that occurred while sending an email?

Hi all!
I need to send emails, and I use a service task for it:

    <serviceTask id="SendEmail_1" name="Sending a notification by email" activiti:type="mail">
      <documentation></documentation>
      <extensionElements>
        <activiti:field name="to">
          <activiti:expression><![CDATA[${to}]]></activiti:expression>
        </activiti:field>
        <activiti:field name="subject">
          <activiti:expression><![CDATA[${subject}]]></activiti:expression>
        </activiti:field>
        <activiti:field name="text">
          <activiti:expression><![CDATA[${body}]]></activiti:expression>
        </activiti:field>
        <activiti:field name="ignoreException">
          <activiti:string><![CDATA[true]]></activiti:string>
        </activiti:field>
        <activiti:field name="charset">
          <activiti:string><![CDATA[utf8]]></activiti:string>
        </activiti:field>
      </extensionElements>
    </serviceTask>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I also need to catch the errors that occur when sending mail. In the user guide, I read that in order to get a description of the error, you need to read from the variables of the process the value of the variable "exceptionVariableName". As you can see above, I added this to the service task, but so far I have not seen that it works. I tried to give him non-existent addresses of recipients, but there was no error. Does it even work? When does it work? Or is there another mechanism for getting error descriptions?

PS I use Activiti 6.0.0.

PSS I tried to add the block below in the 'extensionElements' tag:

        <activiti:field name="exceptionVariableName">
          <activiti:string><![CDATA[error]]></activiti:string>
        </activiti:field>‍‍‍‍‍‍

And it also did not help me (for example, if the recipients are not correct).

PSSS I specified the wrong smtp server host (while creating the process configuration bean), and I got the error description (the Java code for receiving it is presented below), but it is uninformative.

    public void logEmailSending(DelegateExecution execution) {
        Object error = execution.getVariable("error");
        if (error != null)
            logger.error("An error occurred while sending the email: " + error);
    }

it almost solved my problem, but, as I wrote above, I would like to be more concrete by mistake, and it still does not catch the error in the recipients addresses

7 Replies
vidhipanchal
Established Member

Re: How to catch errors that occurred while sending an email?

Hi Max Lich,

Are configure E-mail server configuration in config file?

If not, Please configure like this.

Thanks,

Vidhi

Contcentric

maxlich
Active Member

Re: How to catch errors that occurred while sending an email?

Of course, I have already done it. My emails are being sent and received successfully. But i also want to catch errors if errors occured.

abbask01
Established Member II

Re: How to catch errors that occurred while sending an email?

Have you already create variable named "error" in your execution? The the logic only checks if the process variable (that holds exceptionVariableName) is present in the execution, the mail task will not create a new variable for you.

Regards,
Abbas
maxlich
Active Member

Re: How to catch errors that occurred while sending an email?

However, how i wrote above, it had created the variable with specified name and had written the error text to this variable. The only thing is that this text is not very informative.

abbask01
Established Member II

Re: How to catch errors that occurred while sending an email?

do you get this INFO log "Ignoring email send error:" with the error?

Regards,
Abbas
maxlich
Active Member

Re: How to catch errors that occurred while sending an email?

I did not quite understand you, but, as I checked, an exception message is written to the 'error' variable.

abbask01
Established Member II

Re: How to catch errors that occurred while sending an email?

what message do you get when you print your "error" variable?

The Mail Activity always writes a message ("Could not send e-mail in execution " followed by the executionId) in the exception variable (only if the exception is EmailException) but it logs the specific exception info in the console. so you'll have to create your own service to implement such exception/variable specific logic.

hope it helped

Regards,
Abbas