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
#11
Use this. Put multiple recipients into the to table. The first email is the main recipient, all others will receive a copy. Separate CC header is not needed.

Code:
to = { 'first@example.com', 'second@example.com', 'third@example.com' }

subject = 'CSV'

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

from = '<' .. tostring(settings.from) .. '>'

msgt = {
  headers = {
    ['To'] = to[ 1 ],
    ['From'] = from,
    ['Subject'] = subject,
    ['Content-Type'] = 'text/csv',
    ['Content-Disposition'] = 'attachment; filename="file.csv"',
    ['Content-Transfer-Encoding'] = '7BIT',
  },
  body = ltn12.source.string(csv)
}

settings.source = smtp.message(msgt)
settings.from = from
settings.rcpt = to

res, err = smtp.send(settings)
log(res, err)
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: