Logic Machine Forum
Scripting - Printable Version

+- Logic Machine 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: Scripting (/showthread.php?tid=4085)



Scripting - XSPA2474KW - 09.06.2022

Hello

I have used the scripts below and I have also turned off the 2 step verification in google account 

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 = 'XXXXXX@gmail.com',
    -- smtp username
    user = 'XXXXXX@gmail.com',
    -- smtp password
    password = 'XXXXXXX',
    -- smtp server
    server = 'smtp.gmail.com',
    -- smtp server port
    port = 465,
    -- enable ssl, required for gmail smtp
    secure = 'tlsv1_2',
  }
  -------------------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




require('user.Email')

Email("XXXXXX@gmail.com", "Alarm", "Παραβίαση Σπιτιού")
Email("DDDDDD@gmail.com", "Alarm", "Παραβίαση Σπιτιού")
log(mail("XXXXXX@gmail.com") )



it can't send an email and I have the error below

User script 5: attempt to call global 'mail' (a nil value)
stack traceback

er


RE: Scripting - admin - 09.06.2022

Log the results like this:
Code:
res1, err1 = Email("XXXXXX@gmail.com", "Alarm", "Παραβίαση Σπιτιού")
res2, err2 = Email("DDDDDD@gmail.com", "Alarm", "Παραβίαση Σπιτιού")
log(res1, err1)
log(res2, err2)



RE: Scripting - XSPA2474KW - 09.06.2022

Sorry can't understand.

Where should I add this code?
In send email script?


RE: Scripting - admin - 09.06.2022

Yes, add it to the sending script. The original error is from calling function named mail instead of Email. It is also called without subject/message body.

Code:
require('user.Email')

res1, err1 = Email("XXXXXX@gmail.com", "Alarm", "Παραβίαση Σπιτιού")
res2, err2 = Email("DDDDDD@gmail.com", "Alarm", "Παραβίαση Σπιτιού")

log(res1, err1)
log(res2, err2)



RE: Scripting - XSPA2474KW - 09.06.2022

Hello,

I have added, but nothing.
I get not an error in the log screen of Wiser but also I don't receive any email.


RE: Scripting - admin - 09.06.2022

What do you get in Logs tab (not Error logs)? There must be something otherwise the script didn't run at all.


RE: Scripting - XSPA2474KW - 09.06.2022

Please see the picture


RE: Scripting - admin - 09.06.2022

Due to recent security policy changes Gmail SMTP won't work from scripts. You need to use different email provider.


RE: Scripting - XSPA2474KW - 09.06.2022

And which is the code for the different email provider?


RE: Scripting - XSPA2474KW - 10.06.2022

Hello

can you tell me what should I change?


RE: Scripting - Daniel - 10.06.2022

Script is the same only you must setup email function with details from other email provider.


RE: Scripting - Daniel - 10.06.2022

Have a look here, gmail might actually work
https://forum.logicmachine.net/showthread.php?tid=4076&pid=26361#pid26361