@juanpastas - I did it the way you suggested. But this led to the fact that the file was displayed as text in the body of the message.
This is how it appeared in the letter.
Content-Type: text / csv; encoding = UTF-8; file name = data.csv Content-Transfer-Encoding: 7 bits Content-Disposition: attachment; file name = data.csv Content-ID: xyzxyz [contents of csv file as text]
Then I turned on the message body and it worked.
mail(to: user.email, subject: 'XYZ', body: 'XYZ')
This led to the email having a body and subject that I provided, and the file appeared as an attachment.
source share