11.04.2017, 20:41
1. Admin does not work. I also tried to change the security settings ("sslv23", "tlsv1", "tlsv11" or "tlsv12")
Using 25 port without security settings, everything works!
2. Why does this script send two emails?
-- send an e-mail with attachment
function mailattach(to, subject, message, filename, filedata, mimetype)
-- make sure these settings are correct
local settings = {
-- "from" field, only e-mail must be specified here
from = 'user@domen.com',
-- smtp server
server = 'mail.apollo.lv',
-- smtp server port
port = 25,
}
local smtp = require('socket.smtp')
if type(to) ~= 'table' then
to = { to }
end
for index, email in ipairs(to) do
to[ index ] = '<' .. tostring(email) .. '>'
end
-- escape double quotes in file name
filename = filename:gsub('"', '\\"')
-- message headers and body
settings.source = smtp.message({
headers = {
to = table.concat(to, ', '),
subject = subject,
},
body = {
{
headers = {
['Content-Type'] = 'text/html; charset=utf-8',
},
body = mime.eol(0, message)
},
{
headers = {
['Content-Type'] = mimetype or 'text/plain',
['Content-Disposition'] = 'attachment; filename="' .. filename .. '"',
['Content-Transfer-Encoding'] = 'BASE64',
},
body = ltn12.source.chain(
ltn12.source.string(filedata),
ltn12.filter.chain(mime.encode('base64'), mime.wrap())
)
}
}
})
-- fixup from field
settings.from = '<' .. tostring(settings.from) .. '>'
settings.rcpt = to
return smtp.send(settings)
end
Using 25 port without security settings, everything works!
2. Why does this script send two emails?
-- send an e-mail with attachment
function mailattach(to, subject, message, filename, filedata, mimetype)
-- make sure these settings are correct
local settings = {
-- "from" field, only e-mail must be specified here
from = 'user@domen.com',
-- smtp server
server = 'mail.apollo.lv',
-- smtp server port
port = 25,
}
local smtp = require('socket.smtp')
if type(to) ~= 'table' then
to = { to }
end
for index, email in ipairs(to) do
to[ index ] = '<' .. tostring(email) .. '>'
end
-- escape double quotes in file name
filename = filename:gsub('"', '\\"')
-- message headers and body
settings.source = smtp.message({
headers = {
to = table.concat(to, ', '),
subject = subject,
},
body = {
{
headers = {
['Content-Type'] = 'text/html; charset=utf-8',
},
body = mime.eol(0, message)
},
{
headers = {
['Content-Type'] = mimetype or 'text/plain',
['Content-Disposition'] = 'attachment; filename="' .. filename .. '"',
['Content-Transfer-Encoding'] = 'BASE64',
},
body = ltn12.source.chain(
ltn12.source.string(filedata),
ltn12.filter.chain(mime.encode('base64'), mime.wrap())
)
}
}
})
-- fixup from field
settings.from = '<' .. tostring(settings.from) .. '>'
settings.rcpt = to
return smtp.send(settings)
end