Logic Machine Forum
Email settings - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Gateway (https://forum.logicmachine.net/forumdisplay.php?fid=10)
+--- Thread: Email settings (/showthread.php?tid=2071)



Email settings - Tokatubs - 07.05.2019

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


RE: Email settings - admin - 08.05.2019

Can you send login, password and SMTP server address via PM so we can test locally?


RE: Email settings - Tokatubs - 08.05.2019

(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.


RE: Email settings - admin - 08.05.2019

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?


RE: Email settings - Tokatubs - 08.05.2019

(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..