LogicMachine Forum
email setting - Printable Version

+- LogicMachine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: email setting (/showthread.php?tid=1036)

Pages: 1 2


email setting - gkentsis - 10.10.2017

Hi

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

   

txs


RE: email setting - admin - 10.10.2017

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?


RE: email setting - gkentsis - 10.10.2017

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


RE: email setting - admin - 11.10.2017

Update package from System config-> System > Packages > Click (+) icon

Package for LM4:
https://dl.openrb.com/lm-17/pkg/luasocket_2.0.2-23_mxs.ipk

Package for LM5:
https://dl.openrb.com/lm-17-imx6/pkg/luasocket_2.0.2-23_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.


RE: email setting - gkentsis - 11.10.2017

(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/luasocket_2.0.2-22_mxs.ipk

Package for LM5:
https://dl.openrb.com/lm-17-imx6/pkg/luasocket_2.0.2-22_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



RE: email setting - admin - 11.10.2017

Can you send login/password that your are using via PM so I can check it locally?


RE: email setting - gkentsis - 13.10.2017

(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


RE: email setting - admin - 13.10.2017

Thanks, please update packages again:
Package for LM4:
https://dl.openrb.com/lm-17/pkg/luasocket_2.0.2-23_mxs.ipk
Package for LM5:
https://dl.openrb.com/lm-17-imx6/pkg/luasocket_2.0.2-23_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



RE: email setting - gkentsis - 13.10.2017

(13.10.2017, 08:45)admin Wrote: Thanks, please update packages again:
Package for LM4:
https://dl.openrb.com/lm-17/pkg/luasocket_2.0.2-23_mxs.ipk
Package for LM5:
https://dl.openrb.com/lm-17-imx6/pkg/luasocket_2.0.2-23_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?


RE: email setting - admin - 13.10.2017

It's already there:
https://dl.openrb.com/lm-17-imx6/pkg/luasocket_2.0.2-23_imx6.ipk


RE: email setting - Mrinj - 17.11.2017

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,


RE: email setting - Mrinj - 18.11.2017

Hi again,

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

Best,


RE: email setting - Clémentine - 21.11.2017

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


RE: email setting - admin - 22.11.2017

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.


RE: email setting - joaodaniel.pereira - 27.03.2024

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



RE: email setting - admin - 27.03.2024

Log what the mail function returns as suggested here: https://forum.logicmachine.net/showthread.php?tid=5242&pid=33911#pid33911


RE: email setting - joaodaniel.pereira - 27.03.2024

(27.03.2024, 09:29)admin Wrote: Log what the mail function returns as suggested here: https://forum.logicmachine.net/showthread.php?tid=5242&pid=33911#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]


RE: email setting - Daniel - 27.03.2024

Check this
https://forum.logicmachine.net/showthread.php?tid=4714&pid=30472#pid30472


RE: email setting - Supersoon - 09.05.2024

(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/showthread.php?tid=5242&pid=33911#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


RE: email setting - admin - 09.05.2024

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