You don’t want to use mailcmd for this because it just replaces /usr/sbin/sendmail -t
and Asterisk is going to pass the full formatted email with headers and all into the command. You would have to parse the email contents to do anything with it. Even then, all the variables in voicemail.conf wouldn’t be available. They only exist in voicemail.conf.
What are you actually trying to do with this bash script?