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 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:
https://dl.openrb.com/lm-17/pkg/luasocke...23_mxs.ipk

Package for LM5:
https://dl.openrb.com/lm-17-imx6/pkg/lua...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:
https://dl.openrb.com/lm-17/pkg/luasocke...22_mxs.ipk

Package for LM5:
https://dl.openrb.com/lm-17-imx6/pkg/lua...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:
https://dl.openrb.com/lm-17/pkg/luasocke...23_mxs.ipk
Package for LM5:
https://dl.openrb.com/lm-17-imx6/pkg/lua...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:
https://dl.openrb.com/lm-17/pkg/luasocke...23_mxs.ipk
Package for LM5:
https://dl.openrb.com/lm-17-imx6/pkg/lua...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:
https://dl.openrb.com/lm-17-imx6/pkg/lua...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
#15
Hi, 

What is wrong ? 

Code:
-- user function library

function mail(to, subject, message)
  -- make sure these settings are correct
  local settings = {
    -- "from" field, only e-mail must be specified here
    from = 'XXXXXX@XXXXXX.COM',
    -- smtp username
    user = 'XXXXXX@XXXXXX.COM',
    -- smtp password
    password = 'XXXXXX',
    -- smtp server
    server = 'smtp.office365.com',
    -- smtp server port
    port = 587,
    -- enable tls
    secure = 'tlsv1.3',
    -- 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
    
  log("send email:")
  log(settings)
 
  return smtp.send(settings)
 
end
Reply
#16
Log what the mail function returns as suggested here: https://forum.logicmachine.net/showthrea...1#pid33911
Reply
#17
(27.03.2024, 09:29)admin Wrote: Log what the mail function returns as suggested here: https://forum.logicmachine.net/showthrea...1#pid33911

initscript 27.03.2024 09:44:38
* arg: 1
  * nil
* arg: 2
  * string: timeout

to:
    server = 'smtp.office365.com',
    -- smtp server port
    port = 587,
    -- enable tls
    secure = 'tlsv1_3',
    -- use STARTTLS mode
    starttls = true,

[Image: errir.png]
Reply
#18
Check this
https://forum.logicmachine.net/showthrea...2#pid30472
------------------------------
Ctrl+F5
Reply
#19
(27.03.2024, 09:47)joaodaniel.pereira Wrote:
(27.03.2024, 09:29)admin Wrote: Log what the mail function returns as suggested here: https://forum.logicmachine.net/showthrea...1#pid33911

initscript 27.03.2024 09:44:38
* arg: 1
  * nil
* arg: 2
  * string: timeout

to:
    server = 'smtp.office365.com',
    -- smtp server port
    port = 587,
    -- enable tls
    secure = 'tlsv1_3',
    -- use STARTTLS mode
    starttls = true,

[Image: errir.png]


Hi,

Did you managed to find the correct settings?

I'm also trying to send an email via the same smtp server :-) and getting the following error:

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

Thanks!

Niels
Reply
#20
What you are getting is not an error but a normal result: first return value is 1 = ok, second is nil = no error.
Reply


Forum Jump: