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.

email sending
#7
Morning to everyone,

I tryed to do the same script, in my Comm Funct, I have:
Code:
function mail(to, subject, message)
  -- make sure these settings are correct
  local settings = {
--    "from" field, only e-mail must be specified here
    from ='al*******@gmail.com',
    -- smtp username
    user = 'LM********',
    -- smtp password
    password = '********',
    -- smtp server
    server = 'smtp.gmail.com',
    -- smtp server port
    port = 465,
    -- enable ssl, required for gmail smtp
   -- secure = 'tlsv1_2',
    secure = 'sslv23'
  }

  local smtp = require('socket.smtp')
  local escape = function(v)
    return '<'..tostring..'>'
  end

--  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, ', '),
        to = escape(to),
        subject = subject,
        --['From'] = settings.from,
        ['From'] = from,
      ['Content-type'] = 'text/html; charset=utf-8',
    },
    body = message
  })

  -- fixup from field
  --settings.from = '<' .. tostring(settings.from) .. '>'
-- settings.from = from
  settings.from = escape(settings.from)
  --settings.rcpt = to
  settings.rcpt = { escape(to)}
 
  return smtp.send(settings)
end
 
And in my Event-Script I have:

Code:
curr_value = event.getvalue()
prev_value = storage.get('prev_value')

if curr_value == prev_value then
  return
end

storage.set('prev_value', curr_value)

os.sleep(10)

if curr_value then
  subject = 'Main switch = PERMIT'
  message = '\nState: Desbloqueado'
else
  subject = 'Main switch = PROHIBIT'
  message = '\nState: BLOQUEADO!!'
end

mail('ju*********@gmail.com', subject, message)

The problem is that when I Run my Event script, I don't have any Log or Error, but I neither recive any e-mail in my account.
I will appreciate the help!
Reply


Messages In This Thread
email sending - by Fistel - 05.05.2025, 08:02
RE: email sending - by Daniel - 05.05.2025, 08:48
RE: email sending - by Fistel - 06.05.2025, 16:51
RE: email sending - by Fistel - 07.05.2025, 16:37
RE: email sending - by Erwin van der Zwart - 05.05.2025, 08:55
RE: email sending - by admin - 07.05.2025, 13:32
RE: email sending - by JuLopez - 27.11.2025, 11:25
RE: email sending - by admin - 27.11.2025, 11:32
RE: email sending - by JuLopez - 27.11.2025, 11:52
RE: email sending - by admin - 27.11.2025, 11:55
RE: email sending - by JuLopez - 27.11.2025, 12:08
RE: email sending - by admin - 27.11.2025, 12:18
RE: email sending - by JuLopez - 27.11.2025, 12:20

Forum Jump: