09.05.2021, 08:28
(This post was last modified: 09.05.2021, 08:31 by Erwin van der Zwart.)
Hi,
Couple of things to check:
1) Make sure DNS and DG are set correct in the interface settings (otherwise you have no internet access)
2) Enable https://myaccount.google.com/lesssecureapps on your gmail account (otherwise mail from machines is blocked by google)
3) Use these settings in the common functions:
4) Send a mail
Couple of things to check:
1) Make sure DNS and DG are set correct in the interface settings (otherwise you have no internet access)
2) Enable https://myaccount.google.com/lesssecureapps on your gmail account (otherwise mail from machines is blocked by google)
3) Use these settings in the common functions:
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 = 'yourmail@gmail.com',
-- smtp username
user = 'yourmail@gmail.com',
-- smtp password
password = 'yoursecretpassword',
-- 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
res, err = smtp.send(settings)
return res,err
end
Code:
subject = 'E-mail test'
message = 'Testing e-mail'
res, err = mail('yourrecipient@gmail.com', subject, message)