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.

Scripting
#1
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
Reply
#2
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)
Reply
#3
Sorry can't understand.

Where should I add this code?
In send email script?
Reply
#4
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)
Reply
#5
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.
Reply
#6
What do you get in Logs tab (not Error logs)? There must be something otherwise the script didn't run at all.
Reply
#7
Please see the picture

Attached Files Thumbnail(s)
   
Reply
#8
Due to recent security policy changes Gmail SMTP won't work from scripts. You need to use different email provider.
Reply
#9
And which is the code for the different email provider?
Reply
#10
Hello

can you tell me what should I change?
Reply
#11
Script is the same only you must setup email function with details from other email provider.
------------------------------
Ctrl+F5
Reply
#12
Have a look here, gmail might actually work
https://forum.logicmachine.net/showthrea...1#pid26361
------------------------------
Ctrl+F5
Reply


Forum Jump: