Send attachment with mail not working

Hello,

I have looked into the forms and found a code that should send a email within the workflowautomation and include a attachment with it.

Enclosed my code:

(async (doo: IDoo) => { // do not change this line
// place your code here
doo.workflow.attachment.clearAllDynamicAttachments();

const attachments = doo.model.kunde.originalValue.vollmacht[0]?.fileId || [];

const regex = /base64,(.+)$/;

if (attachments.length) {
    for (const attachment of attachments) {
        const base64Content = attachment.fileData?.match(regex);
        attachment.base64Content = base64Content[1] || '';
        doo.workflow.attachment.addDynamicAttachment(attachment);
    }
}

}) // do not change this line

It does not work, following error occurs:

2024-10-11 20:49:46Z (UTC): The Workflow finished with the result:
TypeError: Cannot read properties of undefined (reading ‘1’)
The workflow will be repeated. Retry count: 2

My second question is: How do I included a answer mail into the automated email?
Since the mail is sent from a noreply email, is it possible to include a “answer mail, f.e. office@office.com”? That the customer that recieves this mail clicks “answer email” this email gets forwared to the “answer mail” email ?

Please help me.

Thank you.