VOICEMAIL : I've tried a lot but mailing is not working

Don’t be afraid about the info that I’m going to post here, but I want you to give as much info as possible. Also I want to show you what I’ve tried.

What do I want
When a voicemail-message is left via the Voicemail()-application, I want the .wav-file send to my mail-address as an attachment.

My mail-setup
I’m not using sendmail as MTA. I have msmtp as MTA and mutt as MUA.
Mailing with mutt and msmtp works well. I have a crontab running that sends me every Saturday my Asterisk logfiles like this :

#!/bin/bash
DATUM=date
mutt -s “LOGFILE verbose $DATUM” -a /var/log/asterisk/verbose jonas.kellens@telenet.be < /dev/null
mutt -s “LOGFILE debug $DATUM” -a /var/log/asterisk/debug jonas.kellens@telenet.be < /dev/null

My /root/.msmtprc-file has the following :

Set default values for all following accounts.

defaults
logfile ~/.msmtp.log

The SMTP server of the provider.

account default
host uit.telenet.be
user my_username
password my_password
from jonas.kellens@telenet.be

The logfile of msmtp (/root/.msmtp.log) shows a successful sending :

May 17 03:01:30 host=uit.telenet.be tls=off auth=off from=jonas.kellens@telenet.be recipients=jonas.kellens@telenet.be mailsize=197590 smtpstatus=250 smtpms
g=‘250 2.0.0 Message accepted for delivery (sR311b0033o2nLm0HR31q7)’ exitcode=EX_OK
(this was last sunday morning at 3 am)

Msmtp vs Sendmail

I have made a symbolic link from sendmail to msmtp :
[root@asterisk asterisk]# ls -l /usr/sbin/sendmail
lrwxrwxrwx 1 root root 20 May 17 21:10 /usr/sbin/sendmail -> /usr/local/bin/msmtp

When I use the default setting in voicemail.conf (mailcmd=/usr/sbin/sendmail -v -t -f), then msmtp will be used. I hoped…

Voicemail.conf

[general]
format=wav49|gsm|wav
serveremail=jonas.kellens@telenet.be
attach=yes
emailsubject=[PBX]: New message ${VM_MSGNUM} in mailbox ${VM_MAILBOX}
emailbody=Dear ${VM_NAME}:\n\n\tjust wanted to let you know you were just left a ${VM_DUR} long message (number ${VM_MSGNUM})\nin mailbox ${VM_MAILBOX} from ${VM_CALLERID}, on ${VM_DATE}, so you might\nwant to check it when you get a chance. Thanks!\n\n\t\t\t\t–Asterisk\n
emaildateformat=%A, %B %d, %Y at %r
mailcmd=/usr/sbin/sendmail -v -t -f

[zonemessages]
eastern=America/New_York|‘vm-received’ Q ‘digits/at’ IMp
central=America/Chicago|‘vm-received’ Q ‘digits/at’ IMp
central24=America/Chicago|‘vm-received’ q ‘digits/at’ H N 'hours’
military=Zulu|‘vm-received’ q ‘digits/at’ H N ‘hours’ 'phonetic/z_p’
european=Europe/Copenhagen|‘vm-received’ a d b ‘digits/at’ HM
belgie=Europe/Brussels|‘vm-received’ Q ‘digits/at’ R

[Voicemail-context]
60 => 4569,Jonas Kellens,jonas.kellens@telenet.be

In my extensions.conf I has the following :

exten => 2000,1,Voicemail(60@voicemail-context,u)

Now, which settings have I tried :

voicemail.conf :

serveremail= Asterisk PBX
serveremail=jonas.kellens@telenet.be

mailcmd=/usr/sbin/sendmail -v -t -f
mailcmd=/usr/local/bin/msmtp -v -t -f
mailcmd=/usr/local/bin/mutt -v -f -a
mailcmd=/usr/sbin/sendmail -v -t -f jonas.kellens@telenet.be
mailcmd=/usr/local/bin/msmtp -v -t -f jonas.kellens@telenet.be

Logfile msmtp

Whenever I call extension 2000, I get the voicemail. I leave a message. There is no fault on the Asterisk CLI.
There is NO entry in the logfile of msmtp (/root/.msmtp.log). No error, no success.

I have the impression that Asterisk is unable to communicate with sendmail or msmtp…

Let’s try something different :

So if Asterisk does not want to send mail, I can maybe write a dialplan that checks for messages and sends the voicemailmessages to my mailaddress.

So I have the following :
[root@asterisk agi-bin]# ls -l /var/lib/asterisk/agi-bin/mail2.sh
-rwxr-xr-x 1 root root 58 May 21 15:16 /var/lib/asterisk/agi-bin/mail2.sh
[root@asterisk agi-bin]# cat /var/lib/asterisk/agi-bin/mail2.sh
mutt -s “$1” -a “$2” jonas.kellens@telenet.be < /dev/null

and this in my dialplan :

exten => 3000,1,NoOp(test mailscript)
exten => 3000,n,System(/var/lib/asterisk/agi-bin/mail2.sh test-email /etc/asterisk/iax.conf)
exten => 3000,n,NoOp(systemstatus : ${SYSTEMSTATUS})

But this does not work according to the output on the CLI :

-- Executing [3000@TCS-personeel-zoiper:1] NoOp("IAX2/jonaskellens-10491", "test mailscript") in new stack
-- Executing [3000@TCS-personeel-zoiper:2] System("IAX2/jonaskellens-10491", "/var/lib/asterisk/agi-bin/mail2.sh test-email /etc/asterisk/iax.conf") in new stack
-- Executing [3000@TCS-personeel-zoiper:3] NoOp("IAX2/jonaskellens-10491", "systemstatus : APPERROR") in new stack

So I’m stuck

There is no way for me to get my voicemail-messages through mailing… and I absolutely want to implement this.

Can someone please help me with this issue ???

Greetingz,
Jonas.

I use exim4 for my email of messages. It is easy to setup, for smtp relay.

So is msmtp I think… Just can’t get Asterisk to speak with it !

What is your configuration for mailcmd= in voicemail.conf then ?

You could do a “Quick and Dirty” Agi to send an email. Or you could just run your email program from a system command

exten => s,1,system(/usr/bin/sendmail -t “blah”)

[quote=“sethsdad0627”]You could do a “Quick and Dirty” Agi to send an email. Or you could just run your email program from a system command

exten => s,1,system(/usr/bin/sendmail -t “blah”)[/quote]

This would indeed be my backup-solution, was it not that I get the following error when my mail-script gets executed :

– Executing [3000@TCS-personeel-zoiper:3] NoOp(“IAX2/jonaskellens-10491”, “systemstatus : APPERROR”) in new stack

See my first post, I already tried this.

This is my mail-command :
exten => 3000,n,System(/var/lib/asterisk/agi-bin/mail2.sh test-email /etc/asterisk/iax.conf)

And mail2.sh is :

[root@asterisk asterisk]# cat /var/lib/asterisk/agi-bin/mail2.sh
mutt -s “$1” -a “$2” jonas.kellens@telenet.be < /dev/null

And yes, it is executable.

Could you maybe tell me why this System()-command fails ?

I am already using mutt in crontab to send me every weekend the logfiles of my Asterisk-server.

Not sure I can tell you exactly why, just a way to “probably” fix it. Do a su - nobody and run your script from that shell. when you get the problem fixed there, Asterisk will run it.

Asterisk has been installed as root and it is now also running as root :

[root@asterisk ~]# ls -l /usr/sbin/asterisk -rwxr-xr-x 1 root root 36029398 Apr 22 15:19 /usr/sbin/asterisk

[root@asterisk ~]# ps aux | grep asterisk root 3037 0.0 0.0 4528 556 ? S May19 0:00 /bin/sh /usr/sbin/safe_asterisk root 3055 0.0 0.3 21788 7532 ? Sl May19 1:59 /usr/sbin/asterisk -f -vvvg -c

So why Asterisk cannot talk with msmtp, or why it cannot execute it via the System()-command… dunno

you have taken an msmtp command and ran it from a /bin/sh as root successfully, then tried the verbatim command from a system call?

This works fine :

I get the e-mail with attachment…

When I execute this with the system()-command in the dialplan I get :

-- Executing [3000@TCS-personeel-zoiper:1] NoOp("IAX2/jonaskellens-15883", "test mailscript") in new stack -- Executing [3000@TCS-personeel-zoiper:2] System("IAX2/jonaskellens-15883", "/var/lib/asterisk/agi-bin/mail2.sh test-email /etc/asterisk/iax.conf") in new stack -- Executing [3000@TCS-personeel-zoiper:3] NoOp("IAX2/jonaskellens-15883", "systemstatus : APPERROR") in new stack

try this
system(/bin/sh /var/lib/asterisk/agi-bin/mail2.sh test-email /etc/asterisk/iax.conf)

[quote=“sethsdad0627”]try this
system(/bin/sh /var/lib/asterisk/agi-bin/mail2.sh test-email /etc/asterisk/iax.conf)[/quote]

Tried it, and this is the result :

-- Executing [3000@TCS-personeel-zoiper:1] NoOp("IAX2/jonaskellens-273", "test mailscript") in new stack -- Executing [3000@TCS-personeel-zoiper:2] System("IAX2/jonaskellens-273", "/bin/sh /var/lib/asterisk/agi-bin/mail2.sh test-email /etc/asterisk/iax.conf") in new stack -- Executing [3000@TCS-personeel-zoiper:3] NoOp("IAX2/jonaskellens-273", "systemstatus : APPERROR") in new stack

This the code in my dialplan :

exten => 3000,1,NoOp(test mailscript) exten => 3000,n,System(/bin/sh /var/lib/asterisk/agi-bin/mail2.sh test-email /etc/asterisk/iax.conf) exten => 3000,n,NoOp(systemstatus : ${SYSTEMSTATUS}) exten => 3000,n,Playtones(congestion,10)

Still would like to see a voicemail-solution…

does the command work from “su - nobody”?

The ‘user’ nobody has no shell defined…
What does Asterisk has to do with this specific account ?

[root@asterisk asterisk]# su - nobody This account is currently not available.

[root@asterisk asterisk]# cat /etc/passwd | grep nobody nobody:x:99:99:Nobody:/:/sbin/nologin

Thanks for your help !

asterisk per se does not use the account. this command establishes a “virgin” environment that should run a command as the “least permissioned” user. Edit /etc/passwd and give the account /bin/sh.

This is the info that I gathered :

So I want to send with my little mailscript (which uses my MUA mutt) :

-sh-3.2$ /var/lib/asterisk/agi-bin/mail2.sh test-email /etc/asterisk/iax.conf Error sending message, child exited 78 (). /var/lib/asterisk/agi-bin/mail2.sh: line 2: 389 Segmentation fault mutt -s "$1" -a "$2" jonas.kellens@telenet.be < /dev/null
This is normal as there is no “.muttrc” in the homedirectory of the user ‘nobody’

This is the error-message (above mentioned as 78 ) :

sendmail: account default not found: no configuration file availableAs I said, this is normal…

what do mail2.sh and msmtp.log look like?

First of all, the following does nothing :

Therefore I need a MUA and that is mutt. Mutt + msmtp : I can send mails… from commandline.

mail2.sh :

#!/bin/sh mutt -s "$1" -a "$2" jonas.kellens@telenet.be < /dev/null
Execute rights :

[quote][root@asterisk asterisk]# ls -l /var/lib/asterisk/agi-bin/mail2.sh
-rwxr-xr-x 1 root root 69 May 26 19:43 /var/lib/asterisk/agi-bin/mail2.sh[/quote]

There are no news entries in /root/.msmtp.log

[quote][root@asterisk asterisk]# ls -l /root/.msmtp.log
-rw------- 1 root root 13835 May 26 18:56 /root/.msmtp.log[/quote]

Just those of this weekend from my crontab-script :

[b]May 24 03:02:33 host=uit.telenet.be tls=off auth=off from=jonas.kellens@telenet.be recipients=kristof.teirlinck@thecomputerstore.be mailsize=159234 smtpstat us=250 smtpmsg='250 2.0.0 Message accepted for delivery (vD2X1b0073o2nLm06D2Xia)' exitcode=EX_OK[/b] May 24 23:10:39 host=uit.telenet.be tls=off auth=off from=jonas.kellens@telenet.be recipients=jonas.kellens@telenet.be mailsize=3347 smtpstatus=250 smtpmsg= '250 2.0.0 Message accepted for delivery (vZAf1b0083o2nLm0GZAfZG)' exitcode=EX_OK

This my crontab-script by the way :

[quote]#!/bin/bash
DATUM=date
mutt -s “LOGFILE verbose $DATUM” -a /var/log/asterisk/verbose jonas.kellens@telenet.be < /dev/null
mutt -s “Gespreksinfo op datum : $DATUM” -a /var/log/asterisk/cdr-csv/Master.csv kristof.teirlinck@thecomputerstore.be < /root/scripts/kristof-boodschap[/quote]
(don’t mind the Dutch words…)

what happens if you 777 mail2.sh? Is the -a option getting set (correctly)?

the option -a is to add an attachment… has nothing to do with the ‘mailing’-issue. I can easily drop this…

Why would write-rights be necessary ?

Changed it :

[root@asterisk agi-bin]# ls -l mail2.sh -rwxrwxrwx 1 root root 69 May 26 19:43 mail2.sh

This the result on the Asterisk CLI :

-- Executing [3000@TCS-personeel-zoiper:1] NoOp("IAX2/jonaskellens-16160", "test mailscript") in new stack -- Executing [3000@TCS-personeel-zoiper:2] System("IAX2/jonaskellens-16160", "/bin/sh /var/lib/asterisk/agi-bin/mail2.sh test-email /etc/asterisk/iax.conf") in new stack [May 26 20:30:00] WARNING[607]: chan_iax2.c:2289 __attempt_transmit: Max retries exceeded to host 78.22.173.198 on IAX2/jonaskellens-2578 (type = 6, subclass = 11, ts=60021, seqno=8) [May 26 20:30:03] WARNING[605]: chan_iax2.c:2289 __attempt_transmit: Max retries exceeded to host 78.22.173.198 on IAX2/jonaskellens-2578 (type = 6, subclass = 2, ts=63011, seqno=9) [May 26 20:30:10] WARNING[612]: chan_iax2.c:2289 __attempt_transmit: Max retries exceeded to host 78.22.173.198 on IAX2/jonaskellens-2578 (type = 6, subclass = 11, ts=70023, seqno=10) [May 26 20:30:20] WARNING[606]: chan_iax2.c:2289 __attempt_transmit: Max retries exceeded to host 78.22.173.198 on IAX2/jonaskellens-2578 (type = 6, subclass = 11, ts=80024, seqno=11) [May 26 20:30:24] WARNING[605]: chan_iax2.c:2289 __attempt_transmit: Max retries exceeded to host 78.22.173.198 on IAX2/jonaskellens-2578 (type = 6, subclass = 2, ts=84012, seqno=12) [May 26 20:30:30] WARNING[610]: chan_iax2.c:2289 __attempt_transmit: Max retries exceeded to host 78.22.173.198 on IAX2/jonaskellens-2578 (type = 6, subclass = 11, ts=90026, seqno=13) [May 26 20:30:40] WARNING[604]: chan_iax2.c:2289 __attempt_transmit: Max retries exceeded to host 78.22.173.198 on IAX2/jonaskellens-2578 (type = 6, subclass = 11, ts=100027, seqno=14) [May 26 20:30:45] WARNING[603]: chan_iax2.c:2289 __attempt_transmit: Max retries exceeded to host 78.22.173.198 on IAX2/jonaskellens-2578 (type = 6, subclass = 2, ts=105013, seqno=15) [May 26 20:30:50] WARNING[604]: chan_iax2.c:2289 __attempt_transmit: Max retries exceeded to host 78.22.173.198 on IAX2/jonaskellens-2578 (type = 6, subclass = 11, ts=110028, seqno=16) [May 26 20:30:54] WARNING[603]: chan_iax2.c:2289 __attempt_transmit: Max retries exceeded to host 78.22.173.198 on IAX2/jonaskellens-16160 (type = 6, subclass = 2, ts=42012, seqno=6) [May 26 20:31:00] WARNING[608]: chan_iax2.c:2289 __attempt_transmit: Max retries exceeded to host 78.22.173.198 on IAX2/jonaskellens-2578 (type = 6, subclass = 11, ts=120030, seqno=17) [May 26 20:31:02] WARNING[609]: chan_iax2.c:2289 __attempt_transmit: Max retries exceeded to host 78.22.173.198 on IAX2/jonaskellens-16160 (type = 6, subclass = 11, ts=50018, seqno=7) [May 26 20:31:06] WARNING[608]: chan_iax2.c:2289 __attempt_transmit: Max retries exceeded to host 78.22.173.198 on IAX2/jonaskellens-2578 (type = 6, subclass = 2, ts=126015, seqno=18) [May 26 20:31:10] WARNING[604]: chan_iax2.c:2289 __attempt_transmit: Max retries exceeded to host 78.22.173.198 on IAX2/jonaskellens-2578 (type = 6, subclass = 11, ts=130032, seqno=19) [May 26 20:31:12] WARNING[608]: chan_iax2.c:2289 __attempt_transmit: Max retries exceeded to host 78.22.173.198 on IAX2/jonaskellens-16160 (type = 6, subclass = 11, ts=60020, seqno=8)

The msmtp-logfile does not mention a new entry.

So… there is definitely a change. But is it a good one ?
I need to restart Asterisk from the CLI with ‘restart now’ otherwise my CLI is flooded with the ‘attempt’-message.

couple more thoughts - the 777 might work as 775 - even though you are running asterisk as root, the system call is operating in a non-root fashion thus requiring the second or third level of rwx permissions. I see that you are doing this as an IAX user rather than a local one. You might want to do this as AGI(mail2.sh) or DeadAGI(mail2.sh) instead of System.