Mail-send error when sending emails with attachment


I am trying to attach the uploaded file and send it via Mail-Connector. I am getting the following error:

Failed to send mail: class cannot be cast to class java.lang.String ( and java.lang.String are in module java.base of loader ‘bootstrap’)

below is the xml part of the connector.

<bpmn:serviceTask id="Activity_074ea6w" name="send pdf" camunda:asyncBefore="true">
            <camunda:inputParameter name="to">xx@xx.xx</camunda:inputParameter>
            <camunda:inputParameter name="subject">x</camunda:inputParameter>
            <camunda:inputParameter name="html">x</camunda:inputParameter>
            <camunda:inputParameter name="fileNames">

Does anyone have an idea how to solve the problem?

Thank You.

Hi there @CamSo! I did some digging into this particular error and I have found a few potential solutions that might work for you.

This particular exception is saying that you can’t cast a ByteArray to a Java string. JavaMail FAQ has more information on Java mail.

You may want to try converting your ByteArrayInputStream data structure to an Array list.

this.list2 = Arrays.asList((byte[])in.readObject());

Array.asList()converts your Array of byte primitives to a List.

Note that you can’t cast an array to a list in Java, unfortunately.

I hope this helps! :slight_smile:

Hi @kiran.oliver, thank you for advise. I will try it out.

1 Like

You’re very welcome! I hope it helps! :slight_smile: