How to rename an attachment on an email
I have noticed a problem in some new code I did on one of our productions. I think it is leading to 2 problems.
I have a file, lets call it 1111111111_2300.pdf.
We make the file UNIQUE to avoid an issue. This filename in the working directory gets a session ID Added to it before the .pdf. So lets say it was session ID 9 it would be 1111111111_2300#SID9.pdf in a working directory .
There are further operations to be done on this document before it is sent. For various errors an email is sent back to service users.
Now as part of being really clear that this document was the one that was sent, the attachment should be called 1111111111_2300.pdf.
how best can i attach the file 1111111111_2300#SID9.pdf to display names in the email as 1111111111_2300.pdf
Set tSC = msg.AttachFile($P(fileToAttach,"\",1,*-1),$P(fileToAttach,"\",*))
The code I have currently is incorrect. It calls this
The problem being
- existing code only deletes the file after a rejection not newFile
- Sometimes to attach the file it in somehow isn't finding the file to attach. Now I think this is because windows may be funny in the process of trying to rename the file again just for attaching to an email
There must be a simplier way to do what our requirement is?