15.06.2018, 06:15
For gmail with 2-step verification you can generate a separate password for sending e-mails from LM: https://security.google.com/settings/sec...ppasswords
Latest mail function:
Latest mail function:
Code:
-- send an e-mail
function mail(to, subject, message)
-- make sure these settings are correct
local settings = {
-- "from" field, only e-mail must be specified here
from = 'example@gmail.com',
-- smtp username
user = 'example@gmail.com',
-- smtp password
password = 'mypassword',
-- smtp server
server = 'smtp.gmail.com',
-- smtp server port
port = 465,
-- enable tls, required for gmail smtp
secure = 'tlsv1_2',
}
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
-- fixup from field
local from = '<' .. tostring(settings.from) .. '>'
-- message headers and body
settings.source = smtp.message({
headers = {
to = table.concat(to, ', '),
subject = subject,
['From'] = from,
['Content-type'] = 'text/html; charset=utf-8',
},
body = message
})
settings.from = from
settings.rcpt = to
return smtp.send(settings)
end