Voicemail and TEMP file

Hello everyone.
To develop a project, I need to make an embedded device with asterisk, to send email in some circumstances. I made the script, and now I need to send the output via email.

Unfortunately, I can not use “/bin/mail” directly cause I got an error (segmentation fault), but it is invoked by the voicemail application: I checked voicemail.conf, and I found mailcmd=/bin/mail).
Currently the device sends emails to users by Gmail account, so anything is fine about configuration.
So, I think the voicemail application, when a messages is recorder, store it and the information (e.g. user’s email, the email body as configured on voicemail.conf, etc.) in some folder. Then immediately, it invokes “/bin/mail” (maybe with some parameters) who sends the email, and finally delete it.
In that case, to send my information, it should be enough to store them in a folder, then invoke “/bin/mail”, but until now I failed.

I checked yes /var/spool/asterisk/voicemail/… but, except the recorded emails, I can not find more.

Does someone can help me?
Thank you!

Maybe it easier to ask in this way:
How does the VoiceMail standard application for Asterisk sends email to the users using an external problem (e.g. sendmail)?
Does it stores the email locally before execute the external email program?

Thank you.

It stores in locally, but not as a temporary file. (If you use the IMAP option, it may be different.)

In my case, Asterisk (ok, the VoiceMail application) saves a temp file on the /tmp folder, then it pipes it to /bin/ssmtp for sending by SMTP and finally delete.
In the temp file, it’s included the attached WAV file too (saved as text).
Obviously the voicemail recordings are stored on /var/spool/voicemail/…