--- /dev/null
+From e8b2e65d2130c5b1841dc4a456bfb79aa017a37e Mon Sep 17 00:00:00 2001
+From: Andre Heider <a.heider@gmail.com>
+Date: Wed, 21 Jan 2026 10:28:50 +0100
+Subject: [PATCH] VM_MESSAGEFILE
+
+---
+ apps/app_voicemail.c | 8 ++++++++
+ 1 file changed, 8 insertions(+)
+
+--- a/apps/app_voicemail.c
++++ b/apps/app_voicemail.c
+@@ -5889,6 +5889,7 @@ static int sendmail(char *srcemail,
+ char tmp[80] = "/tmp/astmail-XXXXXX";
+ char tmp2[256];
+ char *stringp;
++ char fname[PATH_MAX] = "";
+
+ if (vmu && ast_strlen_zero(vmu->email)) {
+ ast_log(AST_LOG_WARNING, "E-mail address missing for mailbox [%s]. E-mail will not be sent.\n", vmu->mailbox);
+@@ -5912,7 +5913,14 @@ static int sendmail(char *srcemail,
+ make_email_file(p, srcemail, vmu, msgnum, context, mailbox, fromfolder, cidnum, cidname, attach, attach2, format, duration, attach_user_voicemail, chan, category, 0, flag, msg_id);
+ fclose(p);
+ snprintf(tmp2, sizeof(tmp2), "( %s < %s ; rm -f %s ) &", mailcmd, tmp, tmp);
++ if (ast_strlen_zero(attach)) {
++ unsetenv("VM_MESSAGEFILE");
++ } else {
++ snprintf(fname, sizeof(fname), "%s.%s", attach, format);
++ setenv("VM_MESSAGEFILE", fname, 1);
++ }
+ ast_safe_system(tmp2);
++ unsetenv("VM_MESSAGEFILE");
+ ast_debug(1, "Sent mail to %s with command '%s'\n", vmu->email, mailcmd);
+ }
+ return 0;