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 whether you accept or reject these cookies being set.

Email settings
#1
Been trying to get the settings correct using my office365 account. 
But i tried changing this script for the FB_mail. This has i guess different settings.
And the secure is different i believe. I think it is TLS1.2 but dont know.
And i am not getting any error in log.

Has anybody had trouble with other email clients. 
Code:
--- [Function] fbe_mail
--- Send email
--- [Comment]
--- This module will sent email if trigger receive value different than 0.  
--- [Input]
--- Trigger [object]
--- To [value, object, storage]
--- Subject [value, object, storage]
--- Message [value, object, storage]
function fbe_mail(input, to, subject, message)
 if (input and input ~= 0) then
          -- 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 ssl, required for gmail smtp
   secure = 'sslv23',
 }

 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

 -- message headers and body
 settings.source = smtp.message({
   headers = {
     to = table.concat(to, ', '),
     subject = subject,
     ['Content-type'] = 'text/html; charset=utf-8',
   },
   body = message
 })

 -- fixup from field
 settings.from = '<' .. tostring(settings.from) .. '>'
 settings.rcpt = to

 log(smtp.send(settings))
   
 end
end

Tested another script:
-- 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

Now getting this error:

FB Event for 32/1/20 07.05.2019 21:10:01
Library socket/tp:0: attempt to index a nil value
stack traceback:
[C]: in function 'send'
User library FB_Email:52: in function 'fbe_mail'
User script:8: in main chunk
FB Event for 32/1/20 07.05.2019 21:40:31
User script:8: attempt to call global 'fbe_mail' (a nil value)
stack traceback:
User script:8: in main chunk
Reply
#2
Can you send login, password and SMTP server address via PM so we can test locally?
Reply
#3
(08.05.2019, 04:40)admin Wrote: Can you send login, password and SMTP server address via PM so we can test locally?

Pm sent.
Reply
#4
Use these settings (change from/user/password as needed):
Code:
local settings = {
    from = '***',
    user = '***',
    password = '***',
    server = 'smtp.office365.com',
    port = 587,
    secure = 'tlsv1_2',
    starttls = true,
}

If this does not work then you might need to update LuaSocket library. Which firmware version are you running?
Reply
#5
(08.05.2019, 08:51)admin Wrote: Use these settings (change from/user/password as needed):
Code:
 local settings = {
   from = '***',
   user = '***',
   password = '***',
   server = 'smtp.office365.com',
   port = 587,
   secure = 'tlsv1_2',
   starttls = true,
}

If this does not work then you might need to update LuaSocket library. Which firmware version are you running?

HW: LM5 Lite + Ext (i.MX6)

SW: 20180822

Will test it now.

(08.05.2019, 08:51)admin Wrote: Use these settings (change from/user/password as needed):
Code:
 local settings = {
   from = '***',
   user = '***',
   password = '***',
   server = 'smtp.office365.com',
   port = 587,
   secure = 'tlsv1_2',
   starttls = true,
}

If this does not work then you might need to update LuaSocket library. Which firmware version are you running?
This worked great. Thanks for help..
Reply


Forum Jump: