Can't send email from outbound dialplan route

Status
Not open for further replies.

pbz

New Member
Feb 10, 2022
9
0
1
124
I'm trying to send an email from an outbound dialplan and I have the Advanced->Default Settings->Email setup and verified working.

I'm using the example here (see the screen shot): https://www.pbxforums.com/threads/change-outbound-caller-number.2731/post-7769

In an outbound dialplan I have the tag set to action, the type set to lua and the data set to email.lua to@email.com from@email.com ' ' 'Test Email' 'Test Body'

The position of the dialplan entry is right before the bridge to the gateways.

My actual emails were replaced with to@email.com and from@email.com

When I make an outbound call, the email is never sent, but in the logs I see this error:

Code:
e1be75b7-5ba0-4e60-adfc-913605613025 EXECUTE [depth=0] sofia/internal/100@1.1.1.1 lua(email.lua to@email.com from@email.com Test Email Test Body)
e1be75b7-5ba0-4e60-adfc-913605613025 2022-02-22 16:28:28.284341 97.87% [ERR] mod_lua.cpp:202 ...are/freeswitch/scripts/resources/functions/send_mail.lua:240: bad argument #1 to pairs (table expected, got string)

My actual ip address was replaced with 1.1.1.1

I checked send_mail.lua on line 240 and the code is:

Code:
for k,v in pairs(headers) do
    xheaders = xheaders .. ('"%s":"%s",'):format(k, v)
end

I'm not sure where to go from here. Any help is appreciated!
 

Adrian Fretwell

Well-Known Member
Aug 13, 2017
1,414
376
83
Just looking at the example at the bottom of the send_mail.lua file, it looks like the first argument needs to be headers not to@email.com...

Code:
--local headers = {
--    ["X-FusionPBX-Domain-UUID"] = '2d171c4c-b237-49ca-9d76-9cffc1618fa7';
--    ["X-FusionPBX-Domain-Name"] = 'domain.com';
--    ["X-FusionPBX-Email-Type"]    = 'voicemail';
--}
--send_mail(headers, 'alexey@domain.com', {'hello', 'world'})
 
  • Like
Reactions: falk

pbz

New Member
Feb 10, 2022
9
0
1
124
I narrowed down the problem and have a workaround.

The issue is the empty string passed in for the header parameter.

None of my attempts to pass in a different value for the parameter worked so I resorted to editing the email.lua file directly.

Code:
nano /usr/share/freeswitch/scripts/email.lua

And change
Code:
headers = argv[3];
to
Code:
headers = {};

Control X, Y, press return to save the change.

This makes the header variable an empty table which will work if you don't need to pass in custom headers.
 

hamagid

Member
Dec 14, 2020
73
6
8
33
That works, thank you.

How can I send a email with new lines?

I tried with \n but I get a error about a unfinished string.
 
Status
Not open for further replies.