email setting
#1
Hi

our smtp server needs to enable tls. what is the right parameter for secure?

   

txs
Reply
#2
Put tlsv12 there, but in most cases port 587 uses STARTTLS mode, so you need to install updated LuaSocket package. Which hardware are you using?
Reply
#3
(10.10.2017, 12:24)admin Wrote: Put tlsv12 there, but in most cases port 587 uses STARTTLS mode, so you need to install updated LuaSocket package. Which hardware are you using?

I have 1 LM4 

   

and 1 LM5 

   

with last firmware and with luashocket 2.0.2-17 both. 
My smtp server setting are

   

So do i need to install LuaSocket package?
Reply
#4
Update package from System config-> System > Packages > Click (+) icon

Package for LM4:
http://dl.openrb.com/lm-17/pkg/luasocket...23_mxs.ipk

Package for LM5:
http://dl.openrb.com/lm-17-imx6/pkg/luas...3_imx6.ipk

First try with secure = 'starttls',
If it does not work then try secure = 'tlsv12',
In your script put mail function call inside log( ) so you can see an error message in logs if there is any.
Reply
#5
(11.10.2017, 07:59)admin Wrote: Update package from System config-> System > Packages > Click (+) icon

Package for LM4:
http://dl.openrb.com/lm-17/pkg/luasocket...22_mxs.ipk

Package for LM5:
http://dl.openrb.com/lm-17-imx6/pkg/luas...2_imx6.ipk

First try with secure = 'starttls',
If it does not work then try secure = 'tlsv12',
In your script put mail function call inside log( ) so you can see an error message in logs if there is any.

hi

with secure = 'starttls' email() returns

* arg: 1
 * nil
* arg: 2
 * nil


 and with secure = 'tlsv12'

* arg: 1
 * nil
* arg: 2
 * string: closed
Reply
#6
Can you send login/password that your are using via PM so I can check it locally?
Reply
#7
(11.10.2017, 10:27)admin Wrote: Can you send login/password that your are using via PM so I can check it locally?

sent it
Reply
#8
Thanks, please update packages again:
Package for LM4:
http://dl.openrb.com/lm-17/pkg/luasocket...23_mxs.ipk
Package for LM5:
http://dl.openrb.com/lm-17-imx6/pkg/luas...3_imx6.ipk

Replace mail() function in Common functions with this and change from/user/password field values to your access details:
Code:
function mail(to, subject, message)
  -- make sure these settings are correct
  local settings = {
    -- "from" field, only e-mail must be specified here
    from = '...',
    -- smtp username
    user = '...',
    -- smtp password
    password = '...',
    -- smtp server
    server = 'mailgate.cosmotemail.gr',
    -- smtp server port
    port = 587,
    -- enable tls
    secure = 'tlsv1',
    -- use STARTTLS mode
    starttls = true,
  }

  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
Reply
#9
(13.10.2017, 08:45)admin Wrote: Thanks, please update packages again:
Package for LM4:
http://dl.openrb.com/lm-17/pkg/luasocket...23_mxs.ipk
Package for LM5:
http://dl.openrb.com/lm-17-imx6/pkg/luas...3_imx6.ipk

Replace mail() function in Common functions with this and change from/user/password field values to your access details:
Code:
function mail(to, subject, message)
 -- make sure these settings are correct
 local settings = {
   -- "from" field, only e-mail must be specified here
   from = '...',
   -- smtp username
   user = '...',
   -- smtp password
   password = '...',
   -- smtp server
   server = 'mailgate.cosmotemail.gr',
   -- smtp server port
   port = 587,
   -- enable tls
   secure = 'tlsv1',
   -- use STARTTLS mode
   starttls = true,
 }

 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

it works perfect. Thank you very much
Can you send me the package for LogicMachine5 Lite Power?
Reply
#10
It's already there:
http://dl.openrb.com/lm-17-imx6/pkg/luas...3_imx6.ipk
Reply
#11
Hi,
Do I need LuaSocket package for HomelYnk also? Where can I find it?
Can I use the same user script with my u/p server settings?
Best,
Reply
#12
Hi again,

Just wanted to share that I found a solution for my question form this link:
https://www.schneider-electric.com/en/do.../AN011_SL/

Best,
Reply
#13
Hi all,

Can you help me to find the mistake in my script ?

Thanks 

function Email(to, subject, message)
  -- make sure these settings are correct
 
  ---------------BEGINNING OF USER EDITABLE AREA-------------------
  local settings = {
    -- "from" field, only e-mail must be specified here
    from = 'bouvet.clementine@gmail.com',
    -- smtp username
    user = 'bouvet.clementine@gmail.com',
    -- smtp password
    password = 'xxxxx',
    -- smtp server
    server = 'smtp.gmail.com',
    -- smtp server port
    port = 465,
    -- enable ssl, required for gmail smtp
    secure = 'sslv23',
  }
  -------------------END OF USER EDITABLE AREA---------------------

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

  -- message headers and body
  settings.source = smtp.message({
    headers = {
      to = escape(to),
      subject = subject,
    },
    body = message
  })

  -- fixup from field
  settings.from = escape(settings.from)
  settings.rcpt = { escape(to) }

  return smtp.send(settings)
end
Reply
#14
There's no point in using another function, you can just use mail(to, subject, message) from common functions. You should also wrap mail function call with log(mail(...)) to see the mail server response which might contain an error of some sort.
Reply


Forum Jump: