This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Csv file as attachment
#10
(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)
Reply


Messages In This Thread
Csv file as attachment - by PassivPluss - 23.12.2022, 00:54
RE: Csv file as attachment - by admin - 23.12.2022, 08:21
RE: Csv file as attachment - by PassivPluss - 23.12.2022, 10:39
RE: Csv file as attachment - by admin - 23.12.2022, 13:00
RE: Csv file as attachment - by PassivPluss - 26.12.2022, 05:19
RE: Csv file as attachment - by mreds5 - 22.08.2023, 14:41
RE: Csv file as attachment - by admin - 27.12.2022, 07:35
RE: Csv file as attachment - by PassivPluss - 07.01.2023, 15:27
RE: Csv file as attachment - by PassivPluss - 25.01.2023, 20:36
RE: Csv file as attachment - by admin - 26.01.2023, 10:33
RE: Csv file as attachment - by PassivPluss - 03.02.2023, 07:45
RE: Csv file as attachment - by admin - 03.02.2023, 09:11
RE: Csv file as attachment - by PassivPluss - 10.02.2023, 07:22
RE: Csv file as attachment - by admin - 10.02.2023, 08:26

Forum Jump: