Posts: 36
Threads: 19
Joined: Feb 2018
Reputation:
0
Hi,
i have been seeing the next link that explain how to send a email when a KNX object change its value : http://openrb.com/example-sending-email-...desyntax_1
But i have to do a kind of historical to save the value of certain objects every hour, not just one.
So i saw this other link: http://openrb.com/example-export-last-ho...-from-lm2/
The problem here is that i dont need to export CSV file to another FTP Server, i have to generate a email with this file.
Is it possible to do this?
Thanks
Posts: 7771
Threads: 42
Joined: Jun 2015
Reputation:
447
See this thread: https://forum.logicmachine.net/showthread.php?tid=394
Code: if #buffer > 1 then
data = table.concat(buffer, '\r\n')
-- send file as report.csv with text/csv mime type
res, err = mailattach('someone@example.com', 'Report for 2016', 'CSV file attached', 'report.csv', data, 'text/csv')
log(res, err)
end
Posts: 36
Threads: 19
Joined: Feb 2018
Reputation:
0
Thanks, but i have not succeeded. So i have started with something simpler to see my error.
I'm trying to send email on KNX group-adress change using this link: http://openrb.com/example-sending-email-from-lm2/
but i don't receive anything. My version is 2.1.1 and i'm using a gmail account with permissions activated.
What's going on??
Posts: 7771
Threads: 42
Joined: Jun 2015
Reputation:
447
Log what mail function returns. Also, you should not use mail function from that example, it's outdated.
Code: res, err = mail('test@test.com', 'Alert', 'KNX object 1/2/2 value is: ' .. tostring(value))
log(res, err)
Posts: 36
Threads: 19
Joined: Feb 2018
Reputation:
0
(06.06.2018, 09:35)admin Wrote: Log what mail function returns. Also, you should not use mail function from that example, it's outdated.
Code: res, err = mail('test@test.com', 'Alert', 'KNX object 1/2/2 value is: ' .. tostring(value))
log(res, err)
Mail function returns this:
* arg: 1
* nil
* arg: 2
* string: Try again
Posts: 303
Threads: 87
Joined: May 2017
Reputation:
2
(06.06.2018, 09:35)admin Wrote: Log what mail function returns. Also, you should not use mail function from that example, it's outdated.
Code: res, err = mail('test@test.com', 'Alert', 'KNX object 1/2/2 value is: ' .. tostring(value))
log(res, err)
You write the example is outdated. Which is the newest, i am having some problem sending emails. Could be my settings are incorrect.. I have tried using my office 365 account, when the new 2 step verification to gmail stops me from completing the allow third party apps..
Posts: 7771
Threads: 42
Joined: Jun 2015
Reputation:
447
For gmail with 2-step verification you can generate a separate password for sending e-mails from LM: https://security.google.com/settings/sec...ppasswords
Latest mail function:
Code: -- send an e-mail
function mail(to, subject, message)
-- make sure these settings are correct
local settings = {
-- "from" field, only e-mail must be specified here
from = 'example@gmail.com',
-- smtp username
user = 'example@gmail.com',
-- smtp password
password = 'mypassword',
-- smtp server
server = 'smtp.gmail.com',
-- smtp server port
port = 465,
-- enable tls, required for gmail smtp
secure = 'tlsv1_2',
}
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
Posts: 303
Threads: 87
Joined: May 2017
Reputation:
2
I tried using this:
mail('test@test.com', 'Alert', 'KNX object 1/2/2 value is: ' .. tostring(value))
Then i received this by email:
KNX object 2/4/2 value is: nil so i need to put something more in the script i guess.
But i found and other post by Daniel. So i downloaded the user.FB_Email for the FBEditor. Installed it. Put the script you posted over here in the common functions and tried out the FBEditor. This only returns:
FB Resident (sleep 60) 15.06.2018 14:04:21
* arg: 1
* nil
* arg: 2
* string: 535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 https://support.google.com/mail/?p=BadCredentials y13-v6sm1476447lfk.37 - gsmtp
I only wonder why one script can delivere the email and the other one cant. When i thought they both relied one the common Function to work.
Total newbie to this with scripting.
Posts: 7771
Threads: 42
Joined: Jun 2015
Reputation:
447
FB does not use mail from common functions, it comes as a separate user library
Posts: 4654
Threads: 24
Joined: Aug 2017
Reputation:
208
Exactly, you have to edit the FB_Email library and put your email setting there.
------------------------------
Ctrl+F5
Posts: 303
Threads: 87
Joined: May 2017
Reputation:
2
(15.06.2018, 12:30)Daniel. Wrote: Exactly, you have to edit the FB_Email library and put your email setting there.
I found it. And now its working. Thanks for help.
Posts: 22
Threads: 3
Joined: Aug 2019
Reputation:
0
Hi,
Is it possible to add in name of CSV-file the date in yymmdd -format?
Gr.
Geert
Posts: 4654
Threads: 24
Joined: Aug 2017
Reputation:
208
os.date("%F",d) this will give you date in such format 2020-03-06
PS. Please create new thread when you can't find relevant to your question.
------------------------------
Ctrl+F5
|