03.02.2023, 07:45
(26.01.2023, 10:33)admin Wrote: Try changing the msgt variable to this:
Code:msgt = {
headers = {
to = to,
['content-type'] = 'text/csv',
['content-disposition'] = 'attachment; filename="logs.csv"',
['content-transfer-encoding'] = '7BIT',
subject = subject,
},
body = ltn12.source.string(csv)
}
to is already escaped using <> in the script
Tried this but the csv looks like this in outlook?
MjAyMy0wMi0wMyAwODowMCw3MDcwNTc1MDAwNzY1NjEyMzksMjE4NzguOAoyMDIzLTAyLTAzIDA3
OjAwLDcwNzA1NzUwMDA3NjU2MTIzOSwyMTg3Ni41CjIwMjMtMDItMDMgMDY6MDAsNzA3MDU3NTAw
MDc2NTYxMjM5LDIxODcxLjkKMjAyMy0wMi0wMyAwNTowMCw3MDcwNTc1MDAwNzY1NjEyMzksMjE4
NjcuNgoyMDIzLTAyLTAzIDA0OjAwLDcwNzA1NzUwMDA3NjU2MTIzOSwyMTg2My4xCjIwMjMtMDIt
MDMgMDM6MDAsNzA3MDU3NTAwMDc2NTYxMjM5LDIxODU2LjMKMjAyMy0wMi0wMyAwMjowMCw3MDcw
NTc1MDAwNzY1NjEyMzksMjE4NTMuNgoyMDIzLTAyLTAzIDAxOjAwLDcwNzA1NzUwMDA3NjU2MTIz
OSwyMTg1MwoyMDIzLTAyLTAzIDAwOjAwLDcwNzA1NzUwMDA3NjU2MTIzOSwyMTg1Mi4zCjIwMjMt
MDItMDIgMjM6MDAsNzA3MDU3NTAwMDc2NTYxMjM5LDIxODQ3LjMKMjAyMy0wMi0wMiAyMjowMCw3
MDcwNTc1MDAwNzY1NjEyMzksMjE4NDMuNgoyMDIzLTAyLTAyIDIxOjAwLDcwNzA1NzUwMDA3NjU2
MTIzOSwyMTgzOC45
this is the mail script. We tried to make use of table as the integrator wanted to have a cc \ to their own email to see file.
But afterward they said that we couldn't have more than one in to field so we only send to one adress
what about this field underneath? ltn12.filter.chain(mime.encode('base64'), mime.wrap('base64'))
smtp = require('socket.smtp')
mime = require('mime')
ltn12 = require('ltn12')
if type(to) ~= 'table' then
to = { to }
end
for index, email in ipairs(to) do
to[ index ] = '' .. tostring(email) .. ''
end
-- fixup from field
local from = '' .. tostring(settings.from) .. ''
if type(cc) ~= 'table' then
cc = { cc }
end
for index, email in ipairs(cc) do
cc[ index ] = '' .. tostring(email) .. ''
end
msgt = {
headers = {
to = table.concat(to, ', '),
cc = table.concat(cc, ', '),
['content-type'] = 'text/csv',
['content-disposition'] = 'attachment; filename="file.csv"',
['content-transfer-encoding'] = '7BIT',
subject = subject,
},
body = ltn12.source.chain(
ltn12.source.string(csv),
ltn12.filter.chain(mime.encode('base64'), mime.wrap('base64'))
)
}
settings.source = smtp.message(msgt)
settings.from = from -- escape(settings.from)
settings.rcpt = to
res, err = smtp.send(settings)