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 sending
#1
Morning i'm trying to send Email

i followed the steps in the manuel attached, but i can't send email

Attached Files
.pdf   AN011_Wiser_for_KNX_SMS_Mail_Flash_v.1.1.pdf (Size: 748.23 KB / Downloads: 30)
Reply
#2
Log what the mail function returns as suggested here: https://forum.logicmachine.net/showthrea...1#pid33911
------------------------------
Ctrl+F5
Reply
#3
Are you using gmail? If yes did you created an app password in your gmail account and use that in your script?
Reply
#4
(05.05.2025, 08:48)Daniel Wrote: Log what the mail function returns as suggested here: https://forum.logicmachine.net/showthrea...1#pid33911
This is what i have from log

Code:
* arg: 1
  * nil
* arg: 2
  * string: 535-5.7.8 Username and Password not accepted. For more information, go to
535 5.7.8  https://support.google.com/mail/?p=BadCredentials 4fb4d7f45d1cf-5fa77bf1e35sm8035646a12.66 - gsmtp

This is the function i used :
Code:
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 = 'nguenangulrich6@gmail.com',
    -- smtp username
    user = 'nguenangulrich6@gmail.com',
    -- smtp password
    password = '***',
    -- 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

the gmail acount i created is "nguenangulrich6@gmail.com" and the pasword "***"

(05.05.2025, 08:55)Erwin van der Zwart Wrote: Are you using gmail? If yes did you created an app password in your gmail account and use that in your script?

Yes, like in the above message
Reply
#5
You need to enable 2FA and the create app password: https://myaccount.google.com/apppasswords
When adding password to your script remove all spaces so only 16 characters are left.
Reply
#6
(06.05.2025, 16:51)Fistel Wrote:
(05.05.2025, 08:48)Daniel Wrote: Log what the mail function returns as suggested here: https://forum.logicmachine.net/showthrea...1#pid33911
This is what i have from log

Code:
* arg: 1
  * nil
* arg: 2
  * string: 535-5.7.8 Username and Password not accepted. For more information, go to
535 5.7.8  https://support.google.com/mail/?p=BadCredentials 4fb4d7f45d1cf-5fa77bf1e35sm8035646a12.66 - gsmtp

This is the function i used :
Code:
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 = 'nguenangulrich6@gmail.com',
    -- smtp username
    user = 'nguenangulrich6@gmail.com',
    -- smtp password
    password = '***',
    -- 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

the gmail acount i created is "nguenangulrich6@gmail.com" and the pasword "***"

(05.05.2025, 08:55)Erwin van der Zwart Wrote: Are you using gmail? If yes did you created an app password in your gmail account and use that in your script?

Yes, like in the above message
Thank's, it's OK now
Reply
#7
Morning to everyone,

I tryed to do the same script, in my Comm Funct, I have:
Code:
function mail(to, subject, message)
  -- make sure these settings are correct
  local settings = {
--    "from" field, only e-mail must be specified here
    from ='al*******@gmail.com',
    -- smtp username
    user = 'LM********',
    -- smtp password
    password = '********',
    -- smtp server
    server = 'smtp.gmail.com',
    -- smtp server port
    port = 465,
    -- enable ssl, required for gmail smtp
   -- secure = 'tlsv1_2',
    secure = 'sslv23'
  }

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

--  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, ', '),
        to = escape(to),
        subject = subject,
        --['From'] = settings.from,
        ['From'] = from,
      ['Content-type'] = 'text/html; charset=utf-8',
    },
    body = message
  })

  -- fixup from field
  --settings.from = '<' .. tostring(settings.from) .. '>'
-- settings.from = from
  settings.from = escape(settings.from)
  --settings.rcpt = to
  settings.rcpt = { escape(to)}
 
  return smtp.send(settings)
end
 
And in my Event-Script I have:

Code:
curr_value = event.getvalue()
prev_value = storage.get('prev_value')

if curr_value == prev_value then
  return
end

storage.set('prev_value', curr_value)

os.sleep(10)

if curr_value then
  subject = 'Main switch = PERMIT'
  message = '\nState: Desbloqueado'
else
  subject = 'Main switch = PROHIBIT'
  message = '\nState: BLOQUEADO!!'
end

mail('ju*********@gmail.com', subject, message)

The problem is that when I Run my Event script, I don't have any Log or Error, but I neither recive any e-mail in my account.
I will appreciate the help!
Reply
#8
Use this to get the result/error in Logs tab.
Code:
res, err = mail('ju*********@gmail.com', subject, message)
log(res, err)

Don't randomly change the mail() function. You only need to change the settings table, everything else should be kept as is. In your case the 'From' header is invalid because the assigned variable is not defined.
Reply
#9
(27.11.2025, 11:32)admin Wrote: Use this to get the result/error in Logs tab.
Code:
res, err = mail('ju*********@gmail.com', subject, message)
log(res, err)

Don't randomly change the mail() function. You only need to change the settings table, everything else should be kept as is. In your case the 'From' header is invalid because the assigned variable is not defined.

Thanks for the point. I forgot to include the log, but when I run the script again, I get no response from either the log or the error log, even though I added the log before running it. I'm also not receiving the email. I've also removed the "From" from the message body, so it now looks like this (in Comm Func) :
Code:
function mail(to, subject, message)
  local settings = {
--    "from" field, only e-mail must be specified here
    from ='al************@gmail.com',
    -- smtp username
    user = 'LM**********',
    -- smtp password
    password = 's************',
    -- smtp server
    server = 'smtp.gmail.com',
    -- smtp server port
    port = 465,
    -- enable ssl, required for gmail smtp
   -- secure = 'tlsv1_2',
    secure = 'sslv23'
  }
  local smtp = require('socket.smtp')
  local escape = function(v)
    return '<' .. tostring .. '>'
  end
  -- message headers and body
  settings.source = smtp.message({
      headers = {
        to = escape(to),
        subject = subject,
    },
    body = message
  })
  settings.from = escape(settings.from)
  settings.rcpt = { escape(to)}
 
  return smtp.send(settings)
end
Reply
#10
From header is required, mail sending won't work without it. Temporarily modify the event script so it only sends the email without checking the previous value and waiting for 10 seconds.
Reply
#11
(27.11.2025, 11:55)admin Wrote: From header is required, mail sending won't work without it. Temporarily modify the event script so it only sends the email without checking the previous value and waiting for 10 seconds.

Almost fixed, now it's sending me the same error that the collegue:
 
Quote: * string: 535-5.7.8 Username and Password not accepted. For more information
 
I already change the user name and the password, I delete the spaces from the password and give the same name that I use when i create the app password, the "app name"
Reply
#12
Username should be the same as the sending email (from), including @gmail.com
The app password should be 16 characters without spaces.
Reply
#13
(27.11.2025, 12:18)admin Wrote: Username should be the same as the sending email (from), including @gmail.com
The app password should be 16 characters without spaces.

Thank you very much!
It's working!  Smile
Reply


Forum Jump: