Docx with unoconv and Mail
-
I am facing really big issues trying to send a docx by email. ( it is working fine when not sending by mail ).
The mail is sent twice ( It is sent in afterRender )
My afterRender() is called twice ( there is not a isChildProcess property in my req object )
The attachment is corrupted as well.
it seems like the unoconv is being called after the mail was sent, which does not make sense to me.
Demo video
https://www.loom.com/share/6eae6b9bf6c54f339021cb334833f1b5
-
hi! yes, this seems to be a problem of not filtering the execution of your
afterRender
script when detecting there are child requests.it seems like the unoconv is being called after the mail was sent, which does not make sense to me.
to give you more clarity since your script is not filtering child requests, the first mail that is being sent is the one resulting from the
afterRender
execution of a child request/render, so this is why you see a mail being sent before the unoconv starts to process. you can see in your video at the profile logs there are two renders, the request 77 is your main render and the one that starts everything, then there is a request 78 (a child request), which when it finish it runs theafterRender
which sends the first mail, then the request 77 continue and executes the unoconv and when it finish it runs theafterRender
, producing the second mail.how did you check the
isChildRequest
? at the root level (req.isChildRequest
)? since v3 theisChildRequest
property is inside thereq.context
so a proper check in your script should look like this:async function afterRender (req, res) { if (req.context.isChildRequest) { return }
let me know if this resolves your issue.
-
Hi, thank you.
I was able to filter out the child process, now it only sends 1 email. But the generated file is not opening, I think there is something wrong.
-
It is working fine now.
But it only works in .docx, is there a way to wait for the unoconv to finish? Or can I call it directly in the afterRender function?
-
i see, so the problem is that the
afterRender
script runs before the unoconv, this is not intended and it is a bug, we want theafterRender
to run as the last step so user code have the chance to manipulate the final result (like your case which you want to use it for sending email).we have the fix for this ready, it will be released likely later this week or next.
-
That is great, I found a way to fix it,
I disabled the auto unoconv and I am calling it manually inside the afterRender, worked great.